开发者

Merging already pushed commits

O hai everybody,

I'm a git novice and I messed up. I think I need to use rebase, which makes me fall into panic mode. Please help me :-D

So, I cloned a repo on a machine called alice. I did some 20 commits and then tried and failed to push since alice lost Internet connection. So I used an USB stick to move my edited repo to machine called bob, and there I did the pushing and everything went better than expected. Update: at this point I copied my origin to a separate remote (I mo开发者_开发问答ved my project from github to a private repo on my own server). I added this new remote to my repo on alice, but I didn't pull from it or anything, since alice has no Internet connectivity.

Then I returned back to alice, forgot that I already did the push, did 20 more commits. Now I have repo on alice with 40 commits since last push to old origin, remote origin with 20 of those 40 commits already pushed update: and remote dijxtra also with 20 of those 40 commits already pushed. I tried pushing to dijxtra, but it failed (see bottom).

What do I do? I figure this is a quite simple problem with a quite simple solution, but I just can't wrap my head around it... Update: I do not wish to push to origin (which would probably be easy) since it is a public repo and I have added some confidential data which must not be published.

edit: Here is what I get when I try to push the newest version (40 commits). This is me on bob trying to push repo coiped from alice:

nick@rilmir:~/tmp/simulator$ git push dijxtra master
dijxtra@dijxtra.net's password:
To dijxtra@dijxtra.net:git/simulator.git
 ! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to 'dijxtra@dijxtra.net:git/simulator.git'
nick@rilmir:~/tmp/simulator$

edit2: Now I remembered: I'm not pushing to origin. That's right, this might be the problem. Let me update the post. Updates are in italic.


If the initial 20 commits on Alice are identical to the 20 commits that exist on your remote repo, you should just be able to push up from Alice, and it will handle adding the 20 new commits to the remote repo.

If you're at all worried about messing up the local repo on Alice, duplicate the repo first, then try your push (however in this case I wouldn't worry, as you're initially just going to push from Alice to Remote, so there'll be no change to the local repo on Alice). Git is usually quite helpful with its error messages, so if that doesn't work let me know what the error message is.


It's easy. From alice: git rebase --onto <bob's last commit> <alice's first new commit>

Then you can push.

(Note though, that as another answer states, there's a good chance this isn't necessary if all you did was copy the commits and push them from another machine. They'll have the same commit hashes and git will match it all up. The rebase should be harmless even then though!)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜