I'm merging two git changesets (or perhaps - in the process of git rebase
'ing, which merges changesets) involving file foo
, and have some merge conflicts. The file looks like so:
text appearing in all changesets
<<<<<<< HEAD
text added on the head
=======
something else added on another changeset
>>>>>>> 1babf8ed... commit comment here
more text appearing in all changesets
added text, no conflicts
yet more appearing in all changesets
My question:
For a specific file (like foo
above) How can I display the conflicts contents so that the HEAD revision shows up as removed text, and the other changeset (in my example) shows up as added text? In other words, how can I make some tool treat the part between <<<<<
and =====
as prefixed by -
and the part between >>>>>
and =====
as prefixed by +
, or the other way around?
Notes:
Conflicts aren't diff as it is not additions on a side, and deletion on the other one.
That being said, tools like meld, kdiff3, or p4merge are able to display conflicts in "side by side" view to help you fix them.
Edit:
For example:
Given the situation created through this script:
#!/usr/bin/env bash
git init demoRepo
cd demoRepo
git commit --allow-empty -m "Init"
for i in {1..10}; do
echo $i >> myFile.txt
git commit -m "Add ${i} to my file" -- myFile.txt
done
git checkout -b branch2 HEAD~5
for i in A B C D E; do
echo $i >> myFile.txt
git commit -m "Add ${i} to my file" -- myFile.txt
done
git merge master
We have a conflict inside myFile.txt
.
Set meld
to be your mergetool
with:
git config --global merge.tool meld
# Use `--local` if you want this setting to be only in current repository
Then call it with:
git mergetool
# You may also call it without (pre)defining the tool in config, like:
# git mergetool --tool=meld
Meld should know display you conflict with a "side by side" view.
Edit: git diff
will show all diffs between the two revisions, which may include a lot of diffs that don't cause a merge conflict. If you want to show merge conflict diffs only, I don't have a solution yet.
If you're willing to see all diffs between the two revisions, you can simply use git diff
. You'll need to pass it:
-U999999
to show the entire file (by telling it you want that many lines of context around any difference)Example: git diff a829c71 d98ef2a -U999999 example.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With