git restore
git
書き方
git restore [--staged] [-s <commit>] <pathspec>ファイルの中身を戻すgit 2.23の命令です。既定では作業中のファイルを上書きしてコミットしていない修正が消え、--stagedならステージから外すだけです。
よく使うオプション
| オプション | 意味 |
|---|---|
| --staged | unstage the file but keep your edits |
| --worktree | reset the file on disk; this is the default |
| --staged --worktree | both: throw the edits away and unstage |
| -s <commit> | take the content from that commit instead of the index |
| -p | choose hunk by hunk |
例
git restore src/app.tswipes uncommitted edits to that file, with no way back
git restore --staged src/app.tstakes it out of the staging area, edits intact
git restore -s HEAD~2 src/app.tsbrings back the version from two commits ago
取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. git restore は何をしますか。
ファイルの中身を戻すgit 2.23の命令です。既定では作業中のファイルを上書きしてコミットしていない修正が消え、--stagedならステージから外すだけです。
Q. どう打ちますか。
git restore [--staged] [-s <commit>] <pathspec> — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは5個です。全部は man git にあります。このコマンドはgitの仲間です。
関連するコマンド
man ページ: man git-restore