Search code examples
gitgit-cherry-pick

git cherry pick and hightlight all changes with (conflict) markers


I want to add changes from a specific commit using git cherry-pick commitId.

However, it would be very useful to mark all changes (for example with conflict markers) so I can accept them manually.

As a novice I failed to find a solution online. I stumbled upon -no-ff option, hoping this does not automatically make changes, but it did.

Any help appreciated!


Solution

  • To do a "slowed down" cherry-pick and review each change individually, you can use the --no-commit flag (or -n in short form) and use interactive add:

    git cherry-pick -n <commitId>
    
    # at this point, all changes are present but nothing commited yet
    
    git reset
    git add -p
    

    It will then cycle through each chunk of change (even non-conflicts), for you to decide what you need (take, leave, edit, etc.)

    (You could also, instead of resetting/re-adding at the end, just git reset -p and interactively unstage changes you don't want, but the logic might feel a bit backwards for some people, feel free to use it if you prefer)