Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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 :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top