Say I created my own branch from develop
branch, and modified fileA a few times in a few commits, now I want to revert just this file to the state in develop
(without reverting my other changes), is there an easy way of doing this? (I know I could checkout it out from develop
and overwrite it in my branch).
Thanks!
You won't be able to "revert" since that's done on a commit by commit basis (rather than file by file). There are two alternatives though. You can pick which suits you. Let's assume the file in question is quux.c
.
git rebase -i
from the point where you cut off the develop
branch and then manually undo the changes you made to quux.c
in each commit since then. Git will rewrite the commits so that it will look like quux.c
was never changed sicne develop
was cut. git show master:quux.c > quux.c
. This will overwrite quux.c
with the version of the file on master
. Then add it and commit it. This will create an extra "revert" commit but it's simpler than the above. As the other answers correctly indicate, git checkout branch -- file
is more user friendly than the git show
command I've mentioned here though the effect is the same.
You do
git checkout develop -- <path/to/file>
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