Git merge: save only incremental commits and drop everything else?

When performing a merge / redirect, I often come across this scenario: - hit some conflicts - resolve important ones by moving them to the index

Then there is a bunch of non-stationary garbage, and I just want to keep the HEAD version. Ideally, I could just do "git commit && git reset --hard", but git will not let me commit until the material that is still running is expected. I tried "git save stash -keep-index", but that fails. I tried "git diff | patch -Rp1" (and various mutations). I don’t think that any of the git reset modes matches what I want.

There must be a way to just say, "I got what I want, just dropped the others."

+4
source share
1 answer

There is no ready-made solution, but you can create an alias.

You can use:

git checkout HEAD -- <list of files to keep as HEAD>

to indicate that you want to save the specified files as they were in HEAD.

To get a list of remaining conflicts, you can use:

git diff --name-only --diff-filter=U

Then combining it as an alias gives:

alias gitkeeprest="for file in $(git diff --name-only --diff-filter=U); do git checkout HEAD -- $file; done"

With this, you would:

  • Run the merge as usual.
  • Allow the parts that interest you by adding them to the index.
  • Put the remainder back as version HEADby running gitkeeprest.
+2
source

Source: https://habr.com/ru/post/1626707/


All Articles