简体   繁体   中英

Problem with git rebase from remote branch

I'm working with some big project with million lines of code and on one day I've pushed a commit into my_branch . Later I've made the additional change & pushed commit through the Web UI (GitLab UI to be precise). Now I want to pull changes from my_branch to my local env.

If I run git pull --rebase origin my_branch , it gives me a lot of rebase conflicts and leads to files that I have never touched. I have no idea how to merge them and thus resolve all the conflicts... I'm sure that nobody else pushed anything there.

How to overcome this situation? What am I doing wrong here?

Thanks in advance!

One possible solution (and a safer one) is to rename your local branch (and unset its upstream), then fetch the remote one and after that merge one into another locally.

Well, you should save contents of your current branch:

git checkout my_branch
git checkout -b by_branch_saved

Then return to my_branch and make hard reset:

git checkout my_branch 
git reset --hard my_branch <latest_stable_version_without_your_changes>

After all this you are able to execute rebase without problems.

git checkout trunk
git branch -D my_branch
git pull
git checkout my_branch

Re-creation helped me: I just deleted my local branch and pulled changes again from the trunk. Then I switched to my_branch .

That's all. Thanks to everyone!

You are getting conflicts in files you have not touched, but others have. Rebasing remerges your local commits against the remote branch. Any changes you have merged must be merged again. If you have many commits locally, and you do not push them, they build up over time. Rebasing becomes harder and harder.

When you have a longer running task, create a new branch from my_branch . Do normal merges instead of rebasing. This prevents you from having to remerge the same changes over and over. When it comes time to merge your personal branch back in to my_branch use a squash-merge to keep the commit history clean:

git checkout my_branch
git pull
git checkout -b your_branch
git commit
git commit
git fetch
git merge origin/my_branch
git commit
git checkout my_branch
git pull
git merge --squash your_branch
git push origin HEAD

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