开发者

git: 2 developers worked on master branch :(

开发者 https://www.devze.com 2023-02-28 21:53 出处:网络
Well, I didn\'t follow the best practises and I\'m now kind of stuck, not knowning what to do exactly.

Well, I didn't follow the best practises and I'm now kind of stuck, not knowning what to do exactly.

I worked on master branch and another developper did the same. He pushed his changes to origin/master. I did not push mine but just did a couple of commits in local. There is no more development beeing done in my working dir now. How can I clean 开发者_JAVA百科this ?

Is it enough to do a fetch on my side to get the last modif done on origin/master without messing the whole thing up ?


You should be able to just do a git pull from the origin. It will merge the new stuff into your local branch. You can then push your committed local changes to origin as well. If there are any conflicts git will warn you about this and will flag them so you can resolve them manually. There's no need to worry as this is exactly the stuff that git is made for and excels at.


If you run git fetch origin, that will update origin/master and all the other remote-tracking branches. (They're essentially like caches of the state of those branches on origin.)

Now if you just do git merge origin/master, you should be able to do git push origin master since now your master's history will include the history of master from origin.

If you're bothered about preserving a linear history (which many people seem to be), you would do git rebase origin/master before pushing.

As (approximate) shortcuts for doing git fetch origin and then git merge origin/master or git rebase origin/master, you can do:

 git pull origin master

... or:

 git pull --rebase origin master

... but personally I think it's clearer do the fetch and merge/rebase separately.


Rebase your changes on top the new master, then push

git rebase origin/master
git push origin

Of course, if there are any merge conflicts, you'l have to resolve them (after resolving git rebase --continue, but the tool will tell you how to do that when it happens).

If you prefer, you can merge the branches (it is still your branch, even if you ever cloned it from master):

git merge origin/master
git push origin

You'll have the same merges and possibly the same conflicts, but the history will be subtly different: a rebase 'groups' all your commits at the end of the new master branch, whereas a merge will have them appear interspersed (with chronological log, not topological order) as they happened in time.

Cheers

0

精彩评论

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