Reputation: 3630
Is there any way to display changes that would be applied by the 'git cherry-pick ' before actually doing anything?
I would like to see a 'git diff' type of list of changes that would be done by the command without actually doing the changes or modifying anything.
Upvotes: 8
Views: 5177
Reputation: 22017
git cherry-pick
doesn't have a --dry-run
option like some other commands.
However, although not exactly what you asked, you could just test it out by leveraging the -n
(--no-commit
) option.
The rollback would be trivial :
(assuming you start on a clean working tree)
# cherry-pick without actually committing
git cherry-pick -n <commit>
# inspect changes
git diff --staged
# wipe all these temporary changes to go back to where you started
git reset --hard
(Note: as rightfully suggested below in comments by Abdull, a better last step could be git cherry-pick --abort
instead of the reset
command)
Upvotes: 11
Reputation: 40021
I've done such "experiments" on a (temporary) branch. Original master/main is left unchanged.
git checkout -b cherry-test
git cherry-pick <sha1>
git show/log/whatever
git checkout master
git branch -D cherry-test
Upvotes: 4
Reputation: 722
I Believe you can do a git diff between the last commit on your branch and the commit you want to cherry-pick like so :
git diff [last-commit-hash] [cherry-pick-commit-hash]
Upvotes: 0