How do I revert a pushed commit back to being unstaged?

David Markowitz

I tried searching for an answer to this, but haven't found anything that matches quite like this problem. Feel free to link me to an answer if there is one already out there.

What I did was commit and push a large number of changes as one commit. I didn't merge that push into master though. I now want to go back to the state before I staged anything, so I can stage the changes into separate commits.

I've tried creating a new branch (saved-work) with the pushed changes, deleting the original remote branch (user-login), then merging the new branch into the original local branch, but that just takes me back to where I am now, with the user-login branch containing nothing to add/commit.

So how do I get all those changes back so I can review and stage them individually (using git add -p)?

Richard Cook

If this is a shared repository and if there is a chance that anybody has already pulled your commits, then don't try to modify your history. If somebody else has already pulled your commits then you'll be fighting a losing battle to reconcile any additional commits that have been made to your errant branch.

If this is not the case, then you'll want to do some combination of resetting, rebasing and pushing with -f.

For example, you could reset using git reset --soft <hash> on the branch in question. This will reset the head of the branch to this commit while leaving all of the subsequent commits unstaged. You could then run git add -p to selectively restage your changes bit by bit.

Once you're happy with the branch you can then push with git push -f. This will forcibly overwrite history on the remote - but it cannot remove any history that anybody else might have pulled.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I revert back to a Git commit?

From Dev

How do I revert a commit only locally?

From Dev

How do i revert a commit and uncommit (?) a file?

From Java

How to revert a merge commit that's already pushed to remote branch?

From Java

How do I "un-revert" a reverted Git commit?

From Java

How do I revert a Git repository to a previous commit?

From Dev

How do I apply this revert commit patch from git?

From Dev

hg: How do I revert (a single file) several commits back?

From Dev

How do I revert back to windows 8 from 8.1?

From Dev

hg: How do I revert (a single file) several commits back?

From Dev

How do I revert back to the online branch of a github project?

From Dev

How do I get back my files marked as deleted in the unstaged changes area of Git staging?

From Dev

How do I recover from a commit --amend if I already pushed the original commit?

From Java

How do I discard unstaged changes in Git?

From Dev

How do I move an unstaged file to untracked?

From Dev

How do I move an unstaged file to untracked?

From Dev

How can I revert specific files of a commit?

From Dev

Revert commits back after the head was changed and pushed

From Dev

source tree how to discard an un pushed commit and go step back

From Dev

How to revert project back to a previous commit in android studio

From Dev

How to revert my remote git repository back to a certain commit?

From Dev

How to undo pushed revert in git?

From Java

How do I add a co-author to latest pushed git commit?

From Dev

How do I revert to ALSA?

From Java

How do I use 'git reset --hard HEAD' to revert to a previous commit?

From Dev

How do I go back to previous Git Commit?

From Dev

When i want to commit staged/unstaged to a new branch, do i need to unstage everything?

From Dev

How do I revert back from sudo add-apt-repository ppa:xorg-edgers/ppa?

From Dev

How do I revert back to default values in HTML/DOM after triggering an event(jQuery)?

Related Related

  1. 1

    How can I revert back to a Git commit?

  2. 2

    How do I revert a commit only locally?

  3. 3

    How do i revert a commit and uncommit (?) a file?

  4. 4

    How to revert a merge commit that's already pushed to remote branch?

  5. 5

    How do I "un-revert" a reverted Git commit?

  6. 6

    How do I revert a Git repository to a previous commit?

  7. 7

    How do I apply this revert commit patch from git?

  8. 8

    hg: How do I revert (a single file) several commits back?

  9. 9

    How do I revert back to windows 8 from 8.1?

  10. 10

    hg: How do I revert (a single file) several commits back?

  11. 11

    How do I revert back to the online branch of a github project?

  12. 12

    How do I get back my files marked as deleted in the unstaged changes area of Git staging?

  13. 13

    How do I recover from a commit --amend if I already pushed the original commit?

  14. 14

    How do I discard unstaged changes in Git?

  15. 15

    How do I move an unstaged file to untracked?

  16. 16

    How do I move an unstaged file to untracked?

  17. 17

    How can I revert specific files of a commit?

  18. 18

    Revert commits back after the head was changed and pushed

  19. 19

    source tree how to discard an un pushed commit and go step back

  20. 20

    How to revert project back to a previous commit in android studio

  21. 21

    How to revert my remote git repository back to a certain commit?

  22. 22

    How to undo pushed revert in git?

  23. 23

    How do I add a co-author to latest pushed git commit?

  24. 24

    How do I revert to ALSA?

  25. 25

    How do I use 'git reset --hard HEAD' to revert to a previous commit?

  26. 26

    How do I go back to previous Git Commit?

  27. 27

    When i want to commit staged/unstaged to a new branch, do i need to unstage everything?

  28. 28

    How do I revert back from sudo add-apt-repository ppa:xorg-edgers/ppa?

  29. 29

    How do I revert back to default values in HTML/DOM after triggering an event(jQuery)?

HotTag

Archive