Polish before git merge?

4

I want to merge user branches into master, however, do some code review & modification before the merge commit.

For example:

o---o---o---o---o master
    \
     o---o---o lucy

Generally, git merge lucy will result as:

                    ,-- "Merge commit"
                    |
o---o---o---o---o---o master
    \              /
     o---o---o----' lucy

and after code review & modify:

                    ,-- "Merge commit"
                    |   ,-- "Code review: 1) fixed EOL char, 2) apply tabsize=4, ..."
                    |   |
o---o---o---o---o---o---o master
    \              /
     o---o---o----' lucy

Instead of above, I want to make the merge commit and code-review commit as a single commit:

                    ,-- "Code review & merge: 1) fixed EOL char, 2) apply tabsize=4, ..."
                    |
o---o---o---o---o---o master
    \              /
     o---o---o----' lucy

I've tried git merge --no-commit, however, after then I can't make later commit as a merge-commit.

Any idea?

Xiè Jìléi

Posted 2011-05-20T01:49:22.177

Reputation: 14 766

git-rebase is probably what you want. – Hello71 – 2011-05-20T01:52:46.683

I guess not, I forgot to say: I can't control users' branches. I'm just fetch them and merge into my master. – Xiè Jìléi – 2011-05-20T02:00:13.167

Answers

2

Try the following workflow. After lucy is done, instead of merging rebase. git checkout lucy; git rebase master. After that point, the last lucy commit would be the same as what a merge from lucy to master would have.

o---o---o---o---o master
                 \
                  o---o---o lucy'

Ask your code reviewer to review lucy. Commit changes as necessary on lucy (the * commit below), then perform the trivial (e.g. possibly fastforward, unless you use --no-ff, which I recommend) merge from lucy on master.

o---o---o---o---o---------------o master
                 \             /
                  o---o---o---* lucy'

The only other option would be to do the merge onto master and NOT share/push your master. Have the code review on your master and then reset away the lucy merge and rebase the code review fix onto lucy and then remerge. Very error and conflict prone.

I later read your comment that you cannot control the user's branch. Your only option is the previous paragraph that ends "very error and conflict prone".

Seth Robertson

Posted 2011-05-20T01:49:22.177

Reputation: 584

1

I you can't control your student's branch, create a new branch of you own to do the merge:

o---o---o---o---o---o master
   \                 \
    |                  * lucy_merge
    \              
     o---o---o----o lucy

Do the merge and subsequent adjustments:

o---o---o---o---o---o master
   \                 \
    |                 o---o---* lucy_merge
    \                /
     o----o----o----o lucy

After that you can either merge master if it's had other commits or if cleanups were necessary:

o---o---o---o---o---o---?---?---* master
   \                 \         /
    |                 o---o---o lucy_merge
    \                /
     o----o----o----o lucy

Or just move the master head and drop the merge branch if there were no changes in master and no cleanup was necessary:

o---o---o---o---o---o
   \                 \         
    |                 o---* master
    \                /
     o----o----o----o lucy

Mat

Posted 2011-05-20T01:49:22.177

Reputation: 6 193

0

Just do a normal merge, then amend the previous commit using git commit --amend when committing your review commit.

Mario Carneiro

Posted 2011-05-20T01:49:22.177

Reputation: 145