出于教育目的,我正在寻找一种方法来直观地演示 a 如何git reset
修改HEAD
和暂存索引。在这种情况下--mixed
,也许--hard
我想获得暂存索引的前后视图,以显示它是如何被修改的。的情况--soft
应该证明它保持不变。
我一直在使用git status
来演示这些过程,发现在“要提交的更改”部分显示待处理的更新git reset
时说“暂存索引未更改”令人困惑。git status
我了解到这git status
并不代表 Staging Index 的状态,而是 Head 和 index 之间的差异。
到目前为止,我一直在使用以下示例进行演示:
git init .
touch reset_lifecycle_file
git add reset_lifecycle_file
git commit -am"initial commit"
echo 'hello git reset' >> reset_lifecycle_file
git commit -am"update content of reset_lifecycle_file"
git log
commit be4aaa98d6976531fdd28aeff52e233087066049
Author: kevzettler <kevzettler@gmail.com>
Date: Thu Nov 30 15:31:16 2017 -0800
update content of reset_lifecycle_file
commit 5e2d74b369f57929673d873302eb7ebd752c2a95
Author: kevzettler <kevzettler@gmail.com>
Date: Thu Nov 30 15:20:43 2017 -0800
initial commit
git status
On branch master
nothing to commit, working tree clean
如果我执行 git reset 到第一次提交,在回购生命的这一点上5e2d74b369f57929673d873302eb7ebd752c2a95
git reset --soft 5e2d74b369f57929673d873302eb7ebd752c2a95
git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: reset_lifecycle_file
这就是混乱的根源。我一直假设“要提交的更改”输出反映了索引的状态,然后假设--soft
一直在修改所有 Git 文档状态都没有发生的索引。
我最近发现了git show
andgit ls-files
命令。我想知道这些是否可以更好地用于可视化这里的过程。
git show --full-index commit 5e2d74b369f57929673d873302eb7ebd752c2a95
Author: kevzettler <kevzettler@gmail.com> Date: Thu Nov 30 15:20:43
2017 -0800
initial commit
diff --git a/reset_lifecycle_file b/reset_lifecycle_file new file mode
100644 index
0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
git show --full-index
似乎将一些索引对象 SHA 附加到输出的末尾。我可以用它来指示对索引的重置更改吗?
git ls-files -s
100644 d7d77c1b04b5edd5acfc85de0b592449e5303770 0 reset_lifecycle_file
git lis-files-s
还有另一个对象 SHA 我可以用它来指示索引的更改吗?在示例中的这一点上,它与输出中的 SHA 不同,git show
是否表明 HEAD 位于新索引 SHA?