Re: Revert a single commit in a single file
- From
Dario Rodriguez <soft.d4rio@gmail.com>
- Date
- Feb 25, 2011, 12:48 UTC
- Message-ID
- <AANLkTimqszvGjVeJHKLPWicDugeOuqbgO1+wy5BO-AE0@mail.gmail.com>
- In-Reply-To
- <4D67A293.2050306@drmicha.warpmail.net>
The most sensible way to do this seems to be:
git checkout HEAD~2 file.c
And your index will show file.c modified, as it will have it's content reverted 2 commits.
The behavior of 'revert' is to revert commits, not files, so it's not expected to work if you say 'git revert <commit> <path>'
Cheers, Dario
On Fri, Feb 25, 2011 at 9:37 AM, Michael J Gruber <git@drmicha.warpmail.net> wrote:
Show 38 quoted lines
> Ævar Arnfjörð Bjarmason venit, vidit, dixit 25.02.2011 12:17: >> On Fri, Feb 25, 2011 at 11:34, Thomas Ferris Nicolaisen >> <tfnico@gmail.com> wrote: >>> I tried asking the same question on the "newbie" list some time ago: >>> >>> http://groups.google.com/group/git-users/browse_thread/thread/d562b4eeac016711 >>> >>> Basically, when I go >>>> git revert <commit> <path> >>> >>> .. my expectation was that a new commit would be made reverting the >>> changes from the old commit, but only for specified path/file. >>> >>> Maybe it's a bit of a corner-case, but still would be nice to have >>> once in a while. What do you think? >> >> It would. What you can do in the meantime is: >> >> git revert <commit> > > Ævar meant to write "git revert --no-commit <commit>" here. (Or there > wouldn't be anything to reset and add.) > >> git reset >> git add <path> >> git commit ... >> git reset --hard # making sure you didn't have uncommited changes earlier > > If you want to revert changes to all files but a few, you can do it the > other way round (revert, checkout HEAD^ -- <path>, commit --amend). > > Cheers, > Michael > -- > To unsubscribe from this list: send the line "unsubscribe git" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >