いくつかのコミットを含む git リポジトリがあります。特定のコミット直後の作業ディレクトリの正確な状態を再現したい(ここでは、行われたすべての変更をコミットしたと仮定します)。
を使用しようとしましgit checkout
たが、このコマンドは作業ディレクトリ内の既存のファイル (目的のコミット後に追加されたもの) を削除しません。
私の問題を説明する簡単な例。次のコマンドを使用してリポジトリを準備しました
u@u-desktop:/tmp/git$ git init
Initialized empty Git repository in /tmp/git/.git/
u@u-desktop:/tmp/git$ echo 'ffff' > first.file
u@u-desktop:/tmp/git$ git add first.file
u@u-desktop:/tmp/git$ git commit -m "Important file was added"
[master (root-commit) fb05f7e] Important file was added
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 first.file
u@u-desktop:/tmp/git$ echo 'Second line' >> first.file
u@u-desktop:/tmp/git$ git commit -m "Important data was added" -a
[master df93d04] Important data was added
1 files changed, 1 insertions(+), 0 deletions(-)
u@u-desktop:/tmp/git$ echo 'ssss' > second.file
u@u-desktop:/tmp/git$ git add second.file
u@u-desktop:/tmp/git$ git commit -m "Second important file was added"
[master b6c106a] Second important file was added
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 second.file
u@u-desktop:/tmp/git$ echo 'tttt' > third.file
u@u-desktop:/tmp/git$ git add third.file
u@u-desktop:/tmp/git$ git commit -m "Third important file was added"
[master 33fce06] Third important file was added
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 third.file
現在、ディレクトリは次のようになっています
u@u-desktop:/tmp/git$ ls
first.file second.file third.file
first.file
次のコンテンツがあります
u@u-desktop:/tmp/git$ cat first.file
ffff
Second line
最初のコミット直後の作業ディレクトリを復元したい ( fb05f7e
)
u@u-desktop:/tmp/git$ git checkout fb05f7e .
u@u-desktop:/tmp/git$ cat first.file
ffff
しかしsecond.file
、third.file
まだディレクトリにあります
u@u-desktop:/tmp/git$ ls
first.file second.file third.file