我如何将我的git存储库切换到特定的提交 [英] How can I switch my git repository to a particular commit
问题描述
在我的git仓库中,我做了5次提交,就像在我的git log中一样:
提交4f8b120cdafecc5144d7cdae472c36ec80315fdc
作者:Michael
日期:Fri Feb 4 15:26:38 2011 -0800
提交b688d46f55db1bc304f7f689a065331fc1715079
作者:Michael
日期:星期一1月31日10:37: 42 2011 -0800
提交b364f9dcec3b0d52666c4f03eb5f6efb7e1e7bda
作者:Michael
日期:Wed Jan 26 13:33:17 2011 -0800
提交4771e26619b9acba3f059b491c6c6d70115e696c
作者:Michael
日期:Wed 1月26日11:16:51 2011 -0800
提交6e559cb951b9bfa14243b925c1972a1bd2586d59
作者:Michael
日期:星期五Jan 21 11: 42:27 2011 -0800
如何在分支中本地回滚以前的4次提交?
换句话说,我如何创建一个没有我最新的4个提交的分支(假设我有从git log提交的SHA的SHA)?
创建一个新的分支(本地):使用提交散列(或部分)它)
git checkout -b new_branch 6e559cb
或者返回HEAD提交的4个提交
$ b
git checkout -b new_branch HEAD〜4
(本地)创建的,您可能想要在具有相同名称的远程机器上复制此更改:如何将我的更改推送到远程分支
对于放弃最后三次提交,请参阅 Lunaryorn的回答。
对于将当前分支HEAD移动到指定提交而不创建新分支,请参阅 Arpiagar的答案 a>。
In my git repository, I made 5 commits, like below in my git log:
commit 4f8b120cdafecc5144d7cdae472c36ec80315fdc
Author: Michael
Date: Fri Feb 4 15:26:38 2011 -0800
commit b688d46f55db1bc304f7f689a065331fc1715079
Author: Michael
Date: Mon Jan 31 10:37:42 2011 -0800
commit b364f9dcec3b0d52666c4f03eb5f6efb7e1e7bda
Author: Michael
Date: Wed Jan 26 13:33:17 2011 -0800
commit 4771e26619b9acba3f059b491c6c6d70115e696c
Author: Michael
Date: Wed Jan 26 11:16:51 2011 -0800
commit 6e559cb951b9bfa14243b925c1972a1bd2586d59
Author: Michael
Date: Fri Jan 21 11:42:27 2011 -0800
How can I roll back my previous 4 commits locally in a branch? In other words, how can I create a branch without my latest 4 commits (assume I have the SHA of that commit from git log)?
To create a new branch (locally):
With the commit hash (or part of it)
git checkout -b new_branch 6e559cb
or to go back 4 commits from HEAD
git checkout -b new_branch HEAD~4
Once your new branch is created (locally), you might want to replicate this change on a remote of the same name: How can I push my changes to a remote branch
For discarding the last three commits, see Lunaryorn's answer below.
For moving your current branch HEAD to the specified commit without creating a new branch, see Arpiagar's answer below.
这篇关于我如何将我的git存储库切换到特定的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!