以下是使用Mercurial的小例子,同样也适用于Git。
我不太明白如何在Git中执行
我有一个小型的Mercurial设置,其中包含4个提交 - 我需要回退一个提交。
现在Git日志怎么样了?
hg update
:我有一个小型的Mercurial设置,其中包含4个提交 - 我需要回退一个提交。
hg init
echo "1" > a.txt; hg commit -A -m "1. commit" a.txt
echo "2" >> a.txt; hg commit -m "2. commit" a.txt
echo "3" >> a.txt; hg commit -m "3. commit" a.txt
echo "4" >> a.txt; hg commit -m "4. commit" a.txt
hg update -r 3
thg # or hg view`
这个图片呈现了以下内容
请注意,我看到了所有四个提交——即包括先前历史和之后的提交
让我尝试使用Git做同样的例子
git init
echo "1" > a.txt; git add a.txt; git commit -m "1. commit" a.txt
echo "2" >> a.txt; git commit -m "2. commit" a.txt
echo "3" >> a.txt; git commit -m "3. commit" a.txt
echo "4" >> a.txt; git commit -m "4. commit" a.txt # gives for me [master 57bb375]
让我看看提交记录:
git log --graph --pretty=format:'%h -%d %s (%cr) <%an>'
* 57bb375 - (HEAD, master) 4. commit (14 minutes ago) <Peter Toft>
* 724a493 - 3. commit (14 minutes ago) <Peter Toft>
* bb38732 - 2. commit (14 minutes ago) <Peter Toft>
* 879c593 - 1. commit (15 minutes ago) <Peter Toft>
非常好 - 四次提交如预期一样。让我回到上一个提交(类似于 hg update)。
git checkout 724a493
现在Git日志怎么样了?
git log --graph --pretty=format:'%h -%d %s (%cr) <%an>'
* 724a493 - (HEAD) 3. commit (19 minutes ago) <Peter Toft>
* bb38732 - 2. commit (19 minutes ago) <Peter Toft>
* 879c593 - 1. commit (19 minutes ago) <Peter Toft>
gitk也只会显示前3个提交吗?
因此,“git checkout”并不仅仅类似于“hg update”。下面的提交在哪里?