0

For test purpose, I have created two files respectively, "admin/1.txt" and "user/2.txt", my command flow is as below:

git add admin/* git commit -m "first commit" git add user/* git commit -m "second commit"

This local commit process could happen multiple times. But after that, I need to rollback all these local-committed-yet-not-pushed files back to there start state (untracked or modified), how could I do that in one line of command? I've tried git reset HEAD~1, but it only rollback 1 step, not all local commitments. Any ideas? Thanks.

KAs
  • 1,818
  • 4
  • 19
  • 37
  • 3
    Possible duplicate of [How to undo the most recent commits in Git?](https://stackoverflow.com/questions/927358/how-to-undo-the-most-recent-commits-in-git) –  Aug 18 '18 at 03:59
  • If you want to go back to the last pushed release, just reset to it. So if you're on master, `git reset --hard origin/master` to make your local `master` equivalent to `origin`'s. – Charles Duffy Aug 18 '18 at 03:59
  • but still, I need to retain my uncommitted changes. If reset hard, all my changes are missing @CharlesDuffy – KAs Aug 18 '18 at 04:00
  • if applying `git reset HEAD~` as guided in that post, it only rollbacks one local commit, not all. @Houseman – KAs Aug 18 '18 at 04:02
  • @KAs, ...I'm not at all sure that the question as currently written conveys that intent to retain your local changes. Perhaps you might edit it to more fully explain what you're trying to do? – Charles Duffy Aug 18 '18 at 15:24

1 Answers1

0

using git checkout -b new_branch save your uncommitted changes in the new branch and then come back to your pervious branch and then use git reset --hard origin/master