Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git merge branch one commit at a time?

Tags:

git

merge

I have a relatively big feature branch that I want to merge with master, and the merge produces quite a lot of conflicts. Is there a way to merge those branches one commit at a time so I could resolve one conflict at a time and check if everything's working?

One solution I can think of is to use rebase instead of merge, but then the history will become flat and I don't want that. I'm ok with creating additional "merge fix" commits, though, if it helps.

like image 868
Dunno Avatar asked Sep 26 '16 09:09

Dunno


People also ask

How do you merge one commit at a time in git?

You could merge "one commit at a time", but it would create a merge commit for each commit you have on the other branch, which is quite heavy. To do that, just look at where you diverged from master , and while on the master branch, issue git merge <commit_id> for each commit starting from that.

Can we commit in merged branch?

Merges a branch into the current branch, creating a merge commit. Use git checkout <target-branch> to switch to the branch into which you want to merge.

How do I merge specific branches?

To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.


1 Answers

You could merge "one commit at a time", but it would create a merge commit for each commit you have on the other branch, which is quite heavy.

To do that, just look at where you diverged from master, and while on the master branch, issue git merge <commit_id> for each commit starting from that.

Otherwise, just resolve the big conflicts once and for all, and everyone reading your commit history will thank you.

A good way to address this problem in the feature would be the regulary merge master in your feature branch.

like image 117
blue112 Avatar answered Oct 07 '22 00:10

blue112