简体   繁体   English

Git - 重置本地更改

[英]Git - reset local changes

I have done some local changes in code stored in Git repo. 我在Git repo中存储的代码中做了一些本地更改。 I don't need these changes anymore, so I would like to discard them and get a clean copy from github. 我不再需要这些更改,所以我想丢弃它们并从github获得一个干净的副本。

When I did a Git pull it gave me a merge conflict error. 当我做了一个Git pull它给了我一个合并冲突错误。

So, I did 所以我做了

git reset --hard

but that did not help. 但这没有帮助。 I also tried 我也试过了

git stash

but still when I try pull from github, it does not allow me to do so. 但是当我尝试从github拉,它仍然不允许我这样做。

Can someone please suggest what would be the best approach to get the latest code from github. 有人可以建议从github获取最新代码的最佳方法。 Should I just delete the local files and then do a git pull? 我应该删除本地文件,然后执行git pull吗?

我会做:

git reset --hard {remote_name_here}/{branch_name_here}

Try: 尝试:

git checkout -f

For a great discussion of the differences between git reset and git checkout, see: 有关git reset和git checkout之间差异的详细讨论,请参阅:

https://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified#_git_reset https://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified#_git_reset

If you just want to get the latest code pushed on remote, you can do that. 如果您只想获取远程推送的最新代码,您可以这样做。

rm -rf ./gitProject

git clone yourRemoteRepo

If you want to leave out all your local changes and get only those from github you can just delete your .git folder and reinitialize it, like that : 如果你想省略所有的本地更改并只从github获取,你可以删除.git文件夹并重新初始化它,如下所示:

rm -rf .git
git init
git remote add origin http://yourGithubUrl.com
git pull

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

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