开发者

git branch roll back to previous commits

开发者 https://www.devze.com 2023-03-26 08:26 出处:网络
I have got twobranches (master and secondary开发者_JAVA百科) at most recent commit. I need the older commit ed state ( 2 unit backward) and so want my secondary branch to move back two commits.

I have got two branches (master and secondary开发者_JAVA百科) at most recent commit. I need the older commit ed state ( 2 unit backward) and so want my secondary branch to move back two commits.

How do I do it?


git branch -f secondary secondary~2

This will only change the commit which the branch references and does not interact with the worktree. as such it's a bit safer than going the git reset route. It will not work if the branch is currently checked out, but this is easily solved by switching to another branch, creating a temporary branch, or detaching HEAD (git checkout HEAD^{}). Another possibility would be to use git checkout -B secondary secondary~2, but this will change your worktree.

don't do this, if your secondary branch was already pushed and was publicly available

0

精彩评论

暂无评论...
验证码 换一张
取 消