1

I have a test branch test that was created several days ago. There was a change made to a file file.py in master since then. I need to merge only this change (and nothing else) from master to test. What is the right sequence of commands to do it? I presume the first one is

git checkout test 

but then what? I want to be 100% sure that no other changes get merged into test.

2 Answers 2

3

You can use the cherry-pick command if you know the exact commit in your "master" branch that changed file.py:

git checkout test git cherry-pick COMMIT_SHA 

Otherwise you can do something like:

git checkout test git checkout master -- file.py git commit -m "Your message" 

Edit: I had the branches mixed up. I corrected them.

Sign up to request clarification or add additional context in comments.

3 Comments

Ok thanks. So when I do git commit -m "Your message", is this going to commit into test?
It will commit into "master"
Ah crud. I just realized I had the branches backwards, will amend my answer.
3

You can also check out individual files in git. So, after git checkout test,

you can do

git checkout master path/to/your/file.py

and have just that file from the other branch :-)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.