Gitでstage前の変更を取り消す(checkout)
| 登録日 | :2024/01/31 15:03 |
|---|---|
| カテゴリ | :Git |
stage( git add )前の変更を取り消すには
~ $ git checkout -- <ファイル名>
~ $ git checkout -- <ディレクトリ名>
全変更を取り消す
~ $ git checkout -- .
実行例
templatesのHTMLへの変更を戻した。
まずステータスで変更状態を確認(git add 前)
+[master]
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: templates/pages/post_list.html
modified: templates/pages/post_mark_list.html
no changes added to commit (use "git add" and/or "git commit -a")
tempaltesフォルダで変更されている2つのファイルを取り消したいので、git checkoutにてフォルダを指定して実行する。
(venv)
+[master]
$ git checkout -- templates/
(venv)
再度ステータスを確認すると、変更が取り消されている。
[master]
$ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
(venv)
あとは、実際にファイルを確認して、変更が取り消されていることを確認する。