Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

32
  • 56
    If you added files in B, C or D. the git checkout -f A -- . Will not delete these, you will have to do it manually. I applied this strategy now, thanks Jakub
    – oma
    Commented Mar 31, 2011 at 14:56
  • 22
    Those solutions are not equivalent. The first one doesn't delete newly created files.
    – m33lky
    Commented Jan 26, 2012 at 5:57
  • 13
    @Jerry: git checkout foo might mean checkout branch foo (switch to branch) or checkout file foo (from index). -- is used to disambiguate, e.g. git checkout -- foo is always about file. Commented Jan 23, 2013 at 2:34
  • 157
    In addition to great answer. This shorthand works for me git revert --no-commit D C B
    – welldan97
    Commented Aug 9, 2013 at 12:34
  • 12
    @welldan97: Thanks for a comment. When writing this answer git revert didn't accept multiple commits; it is quite new addition. Commented Aug 9, 2013 at 18:39