[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge conflict highlight #56

Closed
notramo opened this issue Jan 16, 2024 · 13 comments
Closed

Merge conflict highlight #56

notramo opened this issue Jan 16, 2024 · 13 comments

Comments

@notramo
Copy link
notramo commented Jan 16, 2024

Please add an option to pass only one file to riff, and if it contains merge conflicts, highlight the differences between the 2 chunks.

@classabbyamp

This comment was marked as off-topic.

@walles
Copy link
Owner
walles commented Jan 18, 2024

Two examples, just to see that we're on the same page.

Both examples show the same conflicting changes in branch johan being merged into branch main.

Merge was done with git merge --no-ff johan while on the main branch.

These diffs were done using just git diff after git merge complained about conflicts.

Without diff3 Conflict Style

diff --cc file.txt
index e22c6dd,043d9e8..0000000
--- file.txt
+++ file.txt
@@@ -1,20 -1,20 +1,43 @@@
++<<<<<<< HEAD
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
++=======
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
++>>>>>>> johan

With diff3 Conflict Style

diff --cc file.txt
index e22c6dd,043d9e8..0000000
--- file.txt
+++ file.txt
@@@ -1,20 -1,20 +1,64 @@@
++<<<<<<< HEAD
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
 +This is what the file looks like after being modified in the main branch.
++||||||| bee31e4
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++This is what the file looks like initially.
++=======
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
+ This is what the file looks like in Johan's branch.
++>>>>>>> johan

@walles

This comment was marked as off-topic.

@classabbyamp

This comment was marked as off-topic.

@walles

This comment was marked as off-topic.

@notramo
Copy link
Author
notramo commented Jan 20, 2024

I want to use it to quickly overview what changed in 2 huge hunks. The git merge tool puts merge markers inside the files. There is no + or - sign in the files, only thee <<<<<<<<, ========, and >>>>>>>> lines. I would like to see the diff between the 2 conflicting content to quickly decide how to resolve it. So no + and - needed as in the diff format, however, that can be useful for other use cases too.

@classabbyamp

This comment was marked as off-topic.

@0x5c
Copy link
Contributor
0x5c commented Jan 21, 2024

I'm interested in this too, it would be even more useful than conflict rendering in most editors

Please add an option to pass only one file to riff

That functionality is already in riff as the -f/--file option since 2.26.0

@walles
Copy link
Owner
walles commented Jan 21, 2024

There is no + or - sign in the files

There is actually, if you do git diff after git tells you there's a conflict.

So I think as @classabbyamp was onto there are really two sort of related things riff could potentially be doing:

  1. Stick to only highlighting diffs. In that case, riff would highlight the git diff output when there are conflicts, but riff < file-with-conflict-markers.rs would not.
  2. Highlight random files containing conflict markers (riff < file-with-conflict-markers.rs).

I will treat this ticket as a request for 2.

@classabbyamp
Copy link

perhaps blue would be good for highlighting the <<<<<<<</=========/>>>>>>>>

@walles
Copy link
Owner
walles commented Jan 24, 2024

Here's what I came up with.

The two way merge conflict sections are just compared to each other, with the first being "old" and the second "new".

In the diff3 case, additions relative base is highlighted in sections C1 and C2. In base, anything having been removed in either C1 or C2 will be highlighted. Not sure how to highlight base really but this is something.

diff2 diff3

@walles walles closed this as completed in 1e08af5 Jan 24, 2024
@notramo
Copy link
Author
notramo commented Jan 24, 2024

@walles thanks for implementing this feature so quickly. I work on a project where the differences are hard to spot because no autoformatter has been set up, so this feature is really useful.

@walles
Copy link
Owner
walles commented Feb 5, 2024

@notramo I just had real world use for this myself and it made the conflict much easier to understand.

Thanks for reporting! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants