The revert patch is "newer" than your changes, so it's harder than "git merge" to re-apply your changes. Why not? Because it's harder to "merge" your changes later. Why? Because you are a nice dev working with other nice devs and don't want to wreck their local repos. Your original changes are still in the git log, but they are "undone" with this reverse patch. What? Automatically create a reverse patch to undo your changes. 1) Revert your changes by automatically creating a patch to undo them. You'll have to alert any such people to beware of your "revoked" commits.įor either solution, git log and find the hash of the commit you want to go back to. Just remember that anyone else who has fetched your pushed changes has them, and will continue to have them and can easily get confused by their presence. You can use git push -f after doing the rewind ( git reset -hard) above. You don't have to delete the remote branch. Update: ah, you've pushed them and you want them gone from the remote repository. You'll have to find or remember that number, d97de0e in the above example, somehow.) (If you decide that despite the bleakness you want them back, you need only give them a name before they expire in roughly 3 months. The old one, that has the three extra commits, is now a "junk" branch. It's just that they no longer have any names, and if you do some work and git add and git commit it, that will be on a new branch named my_work_branch. * a1d6424 (HEAD, my_work_branch) here's where you started Will show it them to you: $ git log -graph -decorate -pretty=oneline -abbrev-commit d79de0e The commits you added are still there: $ git log d97de0e If you do this, you find that the name my_work_branch has also been moved: $ git rev-parse my_work_branch Or $ git reset -hard HEAD~3 # use at most one of these But, here's the thing: you can also move the name my_work_branch to point to a1d6424 too: $ git reset -hard a1d6424 You can move HEAD elsewhere with any old git checkout. (This is also where the special name HEAD points.) What you have now is that the branch named my_work_branch (the name you gave earlier) "points to" commit d97de0e, which in turn points to 9a3efe3, which points to 9e80936, which points to a1d6424. * 9a3efe3 attempt #2, getting a little hazier $ git commit -m "attempt #3, looking bleak now"Īt this point git log -graph -decorate -pretty=oneline -abbrev-commit might produce something like: * d97de0e (HEAD, my_work_branch) attempt #3, looking bleak now $ git commit -m "attempt #2, getting a little hazier" $ git commit -m "attempt #1, so far so good" Commits that are neither named nor referenced by some other named commit, eventually go away on their own.įor example, suppose you started with: $ git checkout my_work_branch Be sure to only do this when you're sure you don't need these changes anymore.The general idea in git is that you never delete a commit. If you don't want to keep these changes, simply use the -hard flag. After running the command, you'll find the changes as uncommitted local modifications in your working copy. Note the -soft flag: this makes sure that the changes in undone revisions are preserved. In our example above, we'd like to return to the one before the current revision - effectively making our last commit undone. Reset will rewind your current HEAD branch to the specified revision. In these cases, the "reset" command is your best friend: $ git reset -soft HEAD~1 because you'd like to restructure it extensively - or even discard it altogether! However, of course, there a tons of situations where you really want to undo that last commit. Download Now for Free Undoing the Last Commit
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |