提交之间的Git切换 [英] Git switching between commits
问题描述
我在这里阅读并搜索了很多,但没有找到答案,所以有没有办法像提交分支一样在提交之间进行切换。比方说,我有这些提交: a; b ; c
其中 c
是我最后一次提交,我可以切换回提交 a
吗?或者您必须执行 git diff
并手动修改这些文件?
I read on here and searched a lot but didn't find the answer, so Is there a way to switch between commits like you do with branches.Let's say I have these commits: a;b;c
where c
is my last commit, can I switch back to commit a
? Or you have to do a git diff
and modify the files manually?
推荐答案
<只要输入 git checkout a
即可。也许更有用的是,把 a
作为一个新分支签出,
。 git checkout -b mybranch a
> mybranch
Just type git checkout a
. Or perhaps more usefully, git checkout -b mybranch a
, to checkout a
as a new branch mybranch
.
如果您想要还原 b
和 c
,你可以使用 git revert
,或者从你当前分支的历史记录中完全删除它们,你可以 git rebase -ia
并抛出。
If you want to revert b
and c
, you can use git revert
, or to remove them entirely from your current branch's history, you could git rebase -i a
and throw them out.
即使您打算使用 git diff
,你不必手动进行任何操作。看看 git format-patch
, git apply
和 git am
自动创建和应用修补程序。
Even if you were going to use git diff
, you wouldn't have to do anything manually. Check out git format-patch
, git apply
, and git am
to automate creating and applying patches.
这篇关于提交之间的Git切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!