9

I'm working on a tree which has the following commits:-

aaaaaaa Implement function A
bbbbbbb Implement function B
ccccccc Implement function C

I would like to un-commit the first two , that is , to put these changes again into the staging area. I've learnt that git reset --soft HEAD^ would un-commit the last commit. But I would like to know the way to do it for many commits at once. I'm not sure if git reset --soft HEAD~10 would un-commit the 10th from the last commit or un-commit the last 10 commits.

SloppyJoe
  • 393
  • 4
  • 7
  • `git reset --soft HEAD~~` or `git reset --soft HEAD^^` or `git reset --soft HEAD~2` – Whymarrh Jun 04 '16 at 17:47
  • See also: https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection – Whymarrh Jun 04 '16 at 17:47
  • @Whymarrh None of the answers on stackoverflow or anywhere else answer it for last n commits . You might also write this as an answer and not a comment.Thanks – SloppyJoe Jun 04 '16 at 17:49
  • Possible duplicate of [What are commit-ish and tree-ish in Git?](http://stackoverflow.com/questions/23303549/what-are-commit-ish-and-tree-ish-in-git) – Whymarrh Jun 04 '16 at 17:51
  • Sorry, there are a few, though unfortunately you need to use the exact search terms (i.e. `treeish` or `commitish`). – Whymarrh Jun 04 '16 at 17:52
  • @Whymarrh The reason I asked this on stackoverflow was to know wether `git reset --soft HEAD^^` would uncommit the second last commit and not the last 2 commits. I see no reason for your downvote. Thanks. – SloppyJoe Jun 04 '16 at 17:52
  • I downvoted the question because the answer to this question exists in some form already on the site. – Whymarrh Jun 04 '16 at 17:54
  • @Whymarrh Well, someone like me who doesnt knows the exact terms would never be able to solve his problem(and never ask too) . Atleast the answer for this question would guide them. – SloppyJoe Jun 04 '16 at 17:56
  • Which is more recent: aaaaaa or cccccc? – alex Oct 05 '17 at 15:36

1 Answers1

12

First, be sure that none of the commits you're trying to change have been pushed to the public repository. (From the sounds of it, they have not yet been made public.)

You're on the right track with git reset --soft HEAD^.

HEAD^ is one commit before HEAD. HEAD~4 is four commits before HEAD - or, altogether, five commits back.

Found on GitHub blog

Briana Swift
  • 1,047
  • 8
  • 9
  • Also, props for being aware of staging area vs. working directory as well as difference between `reset --soft`, `--mixed`, and `--hard`. – Briana Swift Jun 04 '16 at 17:54