371

I have several branches where I keep certain commits that I want to apply to my working copy every now and then. Initially I tried cherry-picking but I do not want to have the commit in the target branch later.

So I did cherry-pick + reset HEAD~1 --soft

Is there something simpler like cherry-picking to working copy only?

schoetbi
  • 12,009
  • 10
  • 54
  • 72

7 Answers7

636

Use '-n' flag with the cherry-picking which is "no commit"

See here: http://git-scm.com/docs/git-cherry-pick

git cherry-pick -n <HASH>

To then unstage the staged changes

git reset
Jeremy Moritz
  • 13,864
  • 7
  • 39
  • 43
Igal S.
  • 13,146
  • 5
  • 30
  • 48
24

If you are using Terminal

git cherry-pick -n <HASH>

If you are using Intellij Idea

Settings -> Version Control -> git
untick commit automatically on cherry-pick 
Ravinda Lakshan
  • 1,006
  • 14
  • 14
  • https://intellij-support.jetbrains.com/hc/en-us/community/posts/4404012212882-Setting-Commit-automatically-on-cherry-pick-disappeared-in-2021-2-Beta-2 – Neo Jun 14 '22 at 08:35
17

You can also use apply instead of cherry-pick if you're just trying to apply all the changes you made in a commit to your working directory:

git show <commit> | git apply

This will apply the changes made in but will not add them to staging or create a commit.

adamgy
  • 4,543
  • 3
  • 16
  • 31
14

For IntelliJ users

Settings > Version Control > Git: Uncheck Commit automatically on cherry-pick

enter image description here

Update

This feature was removed and set to true by default. There are many complains and maybe they will return it back.

Meanwhile you can achieve the same result with "Cherry-Pick Selected Changes" from commit view (as mentioned in the thread shared by Neo):

enter image description here

Trayan Momkov
  • 842
  • 1
  • 7
  • 18
6

Simply run:

$ git cherry-pick --no-commit <HASH>
moriarty007
  • 2,054
  • 16
  • 20
2

I was getting errors that error: server/metadata/metadata-preui-prod.xml: No such file or directory

So now I do this

git checkout SHA -- server/metadata && git reset -- server/met adata

Old

git show SHA -- file1.txt file2.txt | git apply -

or all files from SHA

git show SHA | git apply -

How to git-cherry-pick only changes to certain files?

rofrol
  • 14,438
  • 7
  • 79
  • 77
1

To solve this in Visual Studio 2019 without opening a console I went to the "Git Repository" window and right clicked on the Git Commit history and did a cherry pick on the commit I wanted. This commits the cherry pick. But then I did a right click on the commit below and did a "Reset -> Keep changes (--mixed)" which reset the commit but kept the changes uncommitted.

Janspeed
  • 2,644
  • 2
  • 22
  • 22