Git status during merge conflict: Difference between revisions

From genomewiki
Jump to navigationJump to search
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 28: Line 28:


If you had any changes that would conflict with others
If you had any changes that would conflict with others
you would be unable to even start the git pull. Git pull will
you would be unable to even start the git pull. Git pull would
require you to either stash or commit changes to files
require you to either stash or commit changes to files
that others have changed.
that others have changed.
Line 51: Line 51:
This is easily done with this command:
This is easily done with this command:
  git diff origin/master...master    # this shows what YOU changed.
  git diff origin/master...master    # this shows what YOU changed.
Note the triple-dot notation. It is different than double-dot (..)
Note the '''triple-dot''' notation. It is different than double-dot (..)


If that is too verbose, simply do this to see file-level line-count changes:
If that is too verbose, simply do this to see file-level line-count changes:
  git diff --stat origin/master...master
  git diff '''--stat''' origin/master...master


It also works to show just the details for one specific file of interest:
It also works to show just the details for one specific file of interest:

Latest revision as of 05:21, 31 August 2016

Running git status during a merge-conflict can often show a scarily-large number of files. These represent the work of other people in the group. If it has been several days since your last pull, there could be dozens and dozens of files that were changed by other people. You do not want to try to get rid of other people's work. It is part of the merge commit. You do NOT want to try to remove it or you will lose their changes.

This is in fact perfectly normal for merge-commits. There is no need to worry. For each conflicted file, listed under git status:
Resolve the conflicts with the editor, looking for git conflict markers.

vi <somefile>

After resolving the conflict, do git add for each file.

git add <somefile>

When all have been resolved, do

git commit -m 'fixed merge conflict.'

Then follow up with your git push.

But, you insist, "I am an untrusting soul and I want to know what is going into this new merge commit and why."

Here is the logic and the commands for doubters who want to know:

If you had any changes that would conflict with others you would be unable to even start the git pull. Git pull would require you to either stash or commit changes to files that others have changed.

This means that at this point, either you committed or you stashed. If you stashed, those changes are not relevant yet and can be ignored.

So now your changes will be on your local branch (usually master). The new merge commit your are about to complete will have two parents. The first parent will be the HEAD (usually master) and the second parent will be the upstream branch you pull and push to (usually origin/master) which points to the shared repo.

So, you want to know what is on your master branch which has not yet been merged into the shared master. This is the work you have done on the branch since you last pushed.

The problem is that you know master and origin/master, and you want to see only changes along the branch between their common ancestor commit and your local master head.

This is easily done with this command:

git diff origin/master...master    # this shows what YOU changed.

Note the triple-dot notation. It is different than double-dot (..)

If that is too verbose, simply do this to see file-level line-count changes:

git diff --stat origin/master...master

It also works to show just the details for one specific file of interest:

git diff origin/master...master <somefile>

So, if you finish your git merge commit and push, that is the work that is going to be pushed out (plus the usually minor merge-conflict changes which you just made).

If you are sufficiently doubtful person, you may insist on knowing what exactly was changed by all those other git users. So that is easily accomplished. Simply reverse the order of the parameters:

git diff master...origin/master   # this shows what OTHERS changed.

Now that you are fully informed, and satisfied about what is going into your merge commit, remember to finish your commit!

git commit -m 'fixed merge conflict.'
git push