Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
git-rebase is probably what you want. –  Hello71 May 20 '11 at 1:52
    
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 May 20 '11 at 2:00
add comment

3 Answers 3

up vote 2 down vote accepted

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".

share|improve this answer
add comment

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
share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.