0

I would like to reset m repository to an old commit and start tracking the changes from there. It is like 50 commits ago, so git revert is not an option. What should I do?

P.S. update - I also need to push that commit and become the last commit in the repository.

naneri
  • 3,771
  • 2
  • 29
  • 53
  • possible duplicate of [Revert to a previous Git commit](http://stackoverflow.com/questions/4114095/revert-to-a-previous-git-commit) – Joe May 05 '15 at 11:17
  • Joe If i use the method above - I will have to write all the 50 commit SHA manually... – naneri May 05 '15 at 11:50
  • I don't believe you understood the answers in the duplicated question. – Andrew C May 06 '15 at 00:02

2 Answers2

1
$ git reset --hard <commit-hash-of-commit-to-reset-to>

Be aware this will remove all changes since then, if you want to keep the changes and just remove the commits, use --soft instead of hard

Tim
  • 41,901
  • 18
  • 127
  • 145
  • `git reset --soft` [won't update the index](http://git-scm.com/docs/git-reset) so all changes will be staged after the reset is complete. If you want to keep the changes _only_ in your working copy (and not the index) use `git reset --mixed` or simply `git reset`. – Enrico Campidoglio May 05 '15 at 10:50
0

Tim's answer is correct. I am adding few more information I have found on http://git-scm.com/docs/git-reset

$ git commit ...              (1)
$ git reset --soft HEAD~1     (2)
<< edit files as necessary >> (3)
$ git add ....                (4)
$ git commit -c ORIG_HEAD     (5)

(1) This is what you want to undo

(2) This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message1, or both. Leaves working tree as it was before "commit".

(3) Make corrections to working tree files.

(4) Stage changes for commit.

(5) Commit the changes, reusing the old commit message. reset copied the old head to .git/ORIG_HEAD; commit with -c ORIG_HEAD will open an editor, which initially contains the log message from the old commit and allows you to edit it. If you do not need to edit the message, you could use the -C option instead.

SantanuMajumdar
  • 886
  • 1
  • 5
  • 20