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

Add shortcuts to compare incoming/current with common ancestor #236491

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Timmmm
Copy link
Contributor

@Timmmm Timmmm commented Dec 18, 2024

Git has a diff style diff3 or zdiff3 that shows the common ancestor of two conflicting commits in the conflict. For example:

<<<<<<< HEAD
	int c = 2;
||||||| parent of ed293d1 (Capitalise)
	int c;
=======
	int C;
>>>>>>> ed293d1 (Capitalise)

This is enormously useful when resolving conflicts. However sometimes git is dumb and you end up with conflicts that are difficult to follow.

For example suppose you have some really long old code, and you write some new code to replace it. You rebase your change, and find that someone has made a tiny tiny change somewhere in the really long old code. It might be relevant - it could be some change that you also need to apply to your new code. But the conflict just looks like this:

<<<<<<< HEAD
	really
	long
	old
	code
||||||| parent of ed293d1 (Capitalise)
	really
	Long
	old
	code
=======
	new
	code
>>>>>>> ed293d1 (Capitalise)

Not too bad with 4 lines but sometimes it's hundreds, and then you end up visually diffing it, like a cave man.

There is an existing Compare Changes option, but it only compares Current with Incoming. This commit adds two more options to compare the common ancestor with Current or Incoming instead, thus solving the problem once and for all.

This was mostly straightforward. The two tricky bits are:

  1. Apparently you can have more than one common ancestor. I've never seen that so I just don't show the buttons in that case (or pick the first common ancestor if you use the command palette).
  2. What if you don't have diff3 and still run the new compare commands from the command palette? In that case it falls back to not showing any changes.

Git has a diff style `diff3` or `zdiff3` that shows the common ancestor of two conflicting commits in the conflict. For example:

```
<<<<<<< HEAD
	int c = 2;
||||||| parent of ed293d1 (Capitalise)
	int c;
=======
	int C;
>>>>>>> ed293d1 (Capitalise)
```

This is enormously useful when resolving conflicts. However sometimes git is dumb and you end up with conflicts that are difficult to follow.

For example suppose you have some `really long old code`, and you write some `new code` to replace it. You rebase your change, and find that someone has made a tiny tiny change *somewhere* in the really long old code. It *might* be relevant - it could be some change that you also need to apply to your new code. But the conflict just looks like this:

```
<<<<<<< HEAD
	really
	long
	old
	code
||||||| parent of ed293d1 (Capitalise)
	really
	Long
	old
	code
=======
	new
	code
>>>>>>> ed293d1 (Capitalise)
```

Not too bad with 4 lines but sometimes it's hundreds, and then you end up visually diffing it, like a cave man.

There is an existing `Compare Changes` option, but it only compares `Current` with `Incoming`. This commit adds two more options to compare the common ancestor with `Current` or `Incoming` instead, thus solving the problem once and for all.

This was mostly straightforward. The two tricky bits are:

1. Apparently you can have more than one common ancestor. I've never seen that so I just don't show the buttons in that case (or pick the first common ancestor if you use the command palette).
2. What if you don't have `diff3` and still run the new compare commands from the command palette? In that case it falls back to not showing any changes.
@Timmmm
Copy link
Contributor Author

Timmmm commented Dec 18, 2024

Demo:

2024-12-18.15-57-04.mp4

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

Successfully merging this pull request may close these issues.

2 participants