lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

conflict resolver, pick all from branch/stash

Open nagylzs opened this issue 3 years ago • 13 comments

Is your feature request related to a problem? Please describe.

Sometimes when I merge two branches (or a branch and a stash), there are a few files that have lots of conflicts. A good example would be a package-lock.json file. If the two branches are diverged a long time ago, then there can be hundreds of conflicts within that file. Currently, the only available commands are "b: pick all hunks" and "space: pick hunk". I have tried to use "b" to "pick all hunks that are from branch X" or "pick all hunks that are from stash Y" but it does not work that way. I have to go over all hunks and manually pick each of them with "b".

Describe the solution you'd like

When the conflict is a result of merging or rebasing branch X with branch Y, or branch X with stash Y, then there should be an option to accept the complete file version from either X or Y, without going through the hunks.

nagylzs avatar Jul 05 '22 06:07 nagylzs

Good idea. I suppose if it's going to apply to the whole file, then the keybinding should be on the file itself rather than being in the merge panel (it can be both of course).

Do we know if git already provides some CLI functionality to do this? I'm thinking something like git reset Y -- <path> to get what's on branch Y

jesseduffield avatar Jul 05 '22 07:07 jesseduffield

I think the command is:

git checkout f08a63ff4fa7b8479f8c698e5998ee1afcac3a4e file_name

but I'm not sure how it can be done with a file that is inside a stash

nagylzs avatar Jul 05 '22 07:07 nagylzs

Yes, a keybinding on the file would be great.

nagylzs avatar Jul 05 '22 08:07 nagylzs

Could we possibly use git checkout --theirs path/to/file/under/cursor as a keybind during merge conflicts? If so how can we access the aforementioned path to "file under cursor"

pr-313 avatar Jul 13 '22 01:07 pr-313

@pr-313 I believe this should help.

So it's {{.SelectedFile.Name}}?

mark2185 avatar Jul 13 '22 05:07 mark2185

i use this a lot for lock files, git checkout --theirs and git checkout --ours would be sweet to have as keybinds

linde12 avatar Oct 10 '23 14:10 linde12

Having a menu which includes git checkout --theirs <path> and git checkout --ours <path> would be great. I actually had a need for this today. The question is: where do we put it? Some options that come to mind:

  • add the items to the existing 'rebase options' menu which you get by pressing 'm'. Only include the items if a file is selected
  • replace the git merge tool confirmation prompt (which you get by pressing 'shift+M') with a menu which contains the git merge tool option as well as the two new options.

I think we should go with the second option.

I'll chuck a good-first-issue label on this cos it should be easy to implement.

Any chance you're up to the task @linde12 (or @pr-313 / @nagylzs )?

jesseduffield avatar Oct 11 '23 11:10 jesseduffield

@jesseduffield would love to get into go again, but unfortunately time is not on my side right now - ill have to pass on this one

linde12 avatar Oct 11 '23 11:10 linde12

I'd like to give it a shot!

pr-313 avatar Oct 11 '23 13:10 pr-313

any progress here? I have a lock file with hundreds of changes to merge between. is the only option currently to use a cli command? Thanks!

GitMurf avatar Feb 14 '24 15:02 GitMurf