简体   繁体   中英

Remote and local git repository

I have a branch called as masterdev.

I made some commit to that branch, so it is maybe 10 commits ahead from the masterdev that is on the server. But in fact those commits are not good anymore, so I don't want to push them.

I could revert or rebase may be to get the opposite of what I have done in those commit. But that looks like not clear at all I think.

So what I wanted to do is getting the same behavior than git pull origin masterdev if masterdev was behind.

I want to wipe out my local masterdev to get the same as on the server.

I think what you want is - this will reset your local version of masterdev, removing your commits. Then you pull to make sure you're up to date.

git reset --hard origin/masterdev

git pull origin masterdev

If you have nothing worth saving in the index and work-tree, a simple git reset --hard suffices:

$ git status
On branch masterdev
Your branch is ahead of 'origin/masterdev' by 10 commits.
  (use "git push" to publish your local commits)
nothing to commit, working tree clean
$ git fetch origin
... [snip]
$ git reset --hard origin/masterdev

If you do have some work to save, you probably should commit it and do something more complex than just a simple git reset --hard .

(The intermediate git fetch step can be run before or after the git status , though the number of commits ahead and/or behind may change as a result. I recommend avoiding git pull in general, and you won't need it for this case.)

git reset --hard origin/masterdev should do the trick. Then you can simply do git pull origin masterdev

Easy, just git checkout --track origin/master . Will create the branch for you locally and be exactly as the remote version

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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