Skip to content

Instantly share code, notes, and snippets.

@wonbinbk
Created December 4, 2024 23:03
Show Gist options
  • Save wonbinbk/9d9ad8f99246d9ef7ee56553cb9950cf to your computer and use it in GitHub Desktop.
Save wonbinbk/9d9ad8f99246d9ef7ee56553cb9950cf to your computer and use it in GitHub Desktop.
Cherry pick from a commit but only for part of the changes and retain the commit messages, author, etc...
# Reference: https://stackoverflow.com/a/29788254
# The other methods didn't work for me since the commit had a lot of changes and conflicts to a lot of other files. What I came up with was simply
git show SHA -- file1.txt file2.txt | git apply -
# It doesn't actually add the files or do a commit for you so you may need to follow it up with
git add file1.txt file2.txt
git commit -c SHA
# Or if you want to skip the add you can use the --cached argument to git apply
git show SHA -- file1.txt file2.txt | git apply --cached -
# You can also do the same thing for entire directories
git show SHA -- dir1 dir2 | git apply -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment