是否有类似于 svn revert 的 git revert?我需要一个命令来擦除我本地的*所有内容*并将其设置为远程头
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7368824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a git revert similar to svn revert? I need a single command to erase *everything* in my local and set it to remote head
提问by pri
In svn or subclipse, I can simply do a 'revert' on the root project and all my local changes are discarded and src is updated to the latest in HEAD. I don't seem to find an equivalent of this in git though several blogs claim the same.
在 svn 或 subclipse 中,我可以简单地对根项目进行“恢复”,然后丢弃我所有的本地更改,并将 src 更新为 HEAD 中的最新版本。尽管有几个博客声称相同,但我似乎没有在 git 中找到与此等效的内容。
This is what I did:
这就是我所做的:
- committed 10 files from my home mac. did not push.
- committed the same 10 files and more from work computer and PUSHED.
- came back home and I want to take the latest from remote origin/master.
- 从我的家用 mac 提交了 10 个文件。没有推。
- 从工作计算机和 PUSHED 提交了相同的 10 个文件和更多文件。
- 回到家,我想从远程源/主获取最新的。
tried git pull, it brought in changes but warned of conflict
尝试 git pull,它带来了变化,但警告冲突
tried git reset --hard HEAD
, but nothing happened. I still see the committed conflicted changes
尝试过git reset --hard HEAD
,但什么也没发生。我仍然看到提交的冲突更改
I must've tried few other commands I don't remember. I just need to get back to remote head and not worry about what state my local repo is.
我一定尝试过其他一些我不记得的命令。我只需要回到远程负责人,而不用担心我的本地仓库是什么状态。
Help?
帮助?
回答by holygeek
You need to reset to origin/master:
您需要重置为 origin/master:
git reset --hard origin/master
回答by Lily Ballard
git reset --hard @{u}
will throw away all local changes and reset your current branch to its upstream branch. This only works if you've set that information (e.g. by cloning with a recent version of git, or by using git push -u
). If you don't have that info but you know the upstream branch, you can use git reset --hard origin/master
(assuming origin/master
here is the name of the upstream branch).
git reset --hard @{u}
将丢弃所有本地更改并将当前分支重置为其上游分支。这仅在您设置了该信息时才有效(例如,通过使用最新版本的 git 进行克隆,或使用git push -u
)。如果您没有该信息但知道上游分支,则可以使用git reset --hard origin/master
(假设origin/master
这里是上游分支的名称)。
回答by Anahit Serobyan
回答by Carl Norum
You want git reset
, but you probably want to go back one commit earlier, since you committed those files to your HEAD on the home mac.
您想要git reset
,但您可能想早点返回一次提交,因为您已将这些文件提交到家用 Mac 上的 HEAD。
git reset --hard HEAD^
If you're concerned about wrecking something up, you can always do git log
, grab the hash for the commit you want to go back to (discarding your home mac changes), and git reset --hard
to that hash.
如果您担心破坏某些东西,您可以随时执行git log
,获取要返回的提交的哈希(丢弃您的家庭 mac 更改),以及git reset --hard
该哈希。