简体   繁体   English

自上次推送以来撤消git中的更改?

[英]Undo changes in git since the last push?

Newbie question: How do I undo local changes in a git repo back to the last push? 新手问题:如何将git repo中的本地更改撤消回上次推送? I see lots of guidance for rolling back the last commit, or all local changes, but not this case specifically. 我看到了很多关于回滚最后一次提交或所有本地更改的指导,但没有特别针对这种情况。

You find the commit to which you want to go back (let's say foo ) and then say git reset --hard foo . 你找到了你要回去的提交(让我们说foo ),然后说git reset --hard foo The next push you do should be a force push if you want it to go through though. 如果你想让它通过,你下一步的推动应该是强制推动。

Quick&Dirty way: Delete the local branch and create it from the remote one again 快速和脏的方式:删除本地分支并再次从远程分支创建它

git checkout anotherBranch
git branch -D branchA
git checkout -b branchA origin/branchA

Since you have Pushed it that means it will stay in history forever. 既然你推了它就意味着它将永远留在历史中。

Now - Assuming your push is latest on that branch you can.. 现在 - 假设您的推送是最新的分支,您可以..

git revert 
git push origin master #assuming you on master branch

If this is not latest commit - you can choose 如果这不是最新提交 - 您可以选择

git rebase --interactive and remove specific change set git rebase --interactive并删除特定的更改集

You can do a git reset hard for that. 你可以为此做一个git重置。 See man git-reset. 见man git-reset。

In the git log find the hash of the commit you want to go back to. 在git日志中找到要返回的提交的哈希值。 All changes after that commit are undone. 撤消之后的所有更改都将撤消。

By the way here you will find an excellent book for learning about git. 顺便说一下,你会找到一本关于git的好书。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM