开发者

How can I pull from remote Git repository and override the changes in my local repository? [duplicate]

This question already has answers here: Reset local repository branch to be just like remote repository HEAD 开发者_StackOverflow中文版 (25 answers) Closed 8 years ago.

I need to throw away all the changes in my local repository and pull all the code from the remote repository. What is the Git command to do this?


Provided that the remote repository is origin, and that you're interested in master:

git fetch origin
git reset --hard origin/master

This tells it to fetch the commits from the remote repository, and position your working copy to the tip of its master branch.

All your local commits not common to the remote will be gone.


As an addendum, if you want to reapply your changes on top of the remote, you can also try:

git pull --rebase origin master

If you then want to undo some of your changes (but perhaps not all of them) you can use:

git reset SHA_HASH

Then do some adjustment and recommit.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜