git/list[1] front-page[2] threads[3] people[4] search[5] about
 

"git revert" feature suggestion: revert the last commit to a file

From
IMIngo Molnar <mingo@elte.hu>
Date
Feb 5, 2009, 20:21 UTC
Message-ID
<20090205202104.GA11267@elte.hu>

I frequently come across this workflow pattern: i queue up some new change in a topic brach, and there's a test failure within the next 60 minutes or so. I know which file causes the breakage - say kernel/softlockup.c - but i dont know the precise commit ID. I want to revert the change in the integration branch as quickly as possible via a command - without having to wade through 'git log' info and cut&paste-ing commit IDs.

I usually know the topic branch name where the breakage originates from, so i can do this in the integration branch:

   git revert core/softlockup

and it does the right thing and the tests can continue while i take more time in the topic branch to repair the damage there. (at which point i can integrate the fixed/updated commit on top of the reverted commit in the integration branch.)

But often i have other changes queued up in that topic branch as well - and the best, most finegrained information i have about the identity of the commit is the filename it went into.

So i have to do something like:
   git revert $(git log -1 --pretty=format:"%h" kernel/softlockup.c)
(tucked away in a tip-revert-file helper script.)
But it would be so much nicer if i could do the intuitive:
   git revert kernel/softlockup.c
Or at least, to separate it from revision names cleanly, something like:
   git revert -- kernel/softlockup.c

Would something like this be possible in generic Git? It would sure be a nice little touch that i would make use of frequently.

Or is it a bad idea perhaps? Or have i, out of sheer ignorance, failed to discover some nice little shortcut that can give me all of this already?

Thanks,
	Ingo
Next: Johannes Schindelin
Message 1 of 10 in “"git revert" feature suggestion: revert the last commit to a file”
  1. Ingo MolnarFeb 5, 2009
  2. Johannes SchindelinFeb 5, 2009
  3. Junio C HamanoFeb 5, 2009
  4. Randy DunlapFeb 5, 2009
  5. Ingo MolnarFeb 5, 2009
  6. Randy DunlapFeb 5, 2009
  7. Ingo MolnarFeb 5, 2009
  8. Ingo MolnarFeb 5, 2009
  9. Junio C HamanoFeb 6, 2009
  10. Johannes SchindelinFeb 6, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.