hzxu
hzxu

Reputation: 5823

Git merge from branch to master: how to get clean master without branch stuff?

Here is my situation, there is a GIT repository, I am working on master while someone else is working on a branch, say subway, with the following history (say for one single file):

edit:sorry the formatting is not user-friendly, I've updated it as below:

Person A and B are both working on the same file, Person A is working on master with commits: Time1A, Time2A and Time3A changes: added 1, 3, 5 respectively

Person B is working on branch subway with commits: Time1B, Time2B and Time3B changes: added 2, 4, 6 respectively

When PersonB merges from subway to master, the commits history will look like:

Time1A, Time1B, Time2A, Time2B, Time3A, Time3B

and in the file I got: 1,2,3,4,5,6.

If I need to get a clean master before the merge, can I just checkout the commit for Time3A? Does it include stuff merged from subway before Time3?

Thanks

Upvotes: 2

Views: 340

Answers (2)

VonC
VonC

Reputation: 1328712

One better solution would be for B to rebase his/her work on A

(master) -> ... Time1A -- Time2A -- Time3A
                                        \
                                         >--  Time1B' -- Time2B' -- Time3B' (subway)

Then the merge to master is a fast-forward one:

(master) -> ... Time1A -- Time2A -- Time3A --  Time1B' -- Time2B' -- Time3B' (master,subway)

See "git rebase vs git merge".

Upvotes: 2

user149341
user149341

Reputation:

Making a merge in Git only adds to history. It does not modify the past — if you check out a past commit after a merge, that commit will be exactly as it was when that commit was made.

Incidentally, your timeline is not really correct: the two branches are not retroactively commingled like that. A better depiction of the commit history would be:

master -> ... Time1A -- Time2A -- Time3A
                                        \
                                         >-- Merge
                                        /
subway -> ... Time1B -- Time2B -- Time3B

In this history, the commit marked "Merge" has two parents (Time3A and Time3B).

Upvotes: 3

Related Questions