Let's say you have a branch master
and another branch production
, both containing a version of the file prog.py
, as well as many other files. Imagine that you modify many files in the production branch, including prog.py
. Now, what is the best way of having only some changes made on prog.py
in the production
branch be applied to its version in the master
branch?
I started moving to the master
branch and importing the file from the production
branch:
git checkout master
git checkout production -- prog.py
because I was hoping to be able to do git add -p
and select the changes by hand. The problem is that prog.py
is both in the working tree and in the index. How can I remove it from the index without touching the working tree?
Or is there a better way of choosing which changes in prog.py
should be imported from the production
branch into the master
branch?
I'm not sure if this was true when this question was asked, but with a current version of git you can do the following:
git checkout -p production -- prog.py
and you'll get the same interactive hunk-picker you do for most -p
commands.
Making small and granular commits that only do one thing, and then later cherry-picking the changes you also want in the other branch using git cherry-pick $commit_id
would seem like a reasonable approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With