# your commit lives in this branch now :) # remove the last commit from the master branch Oh shit, I accidentally committed something to master that should have been on a brand new branch! # create a new branch from the current state of master Stupid commit message formatting requirements. # follow prompts to change the commit message Oh shit, I need to change the message on my last commit! git commit -amend Warning: You should never amend commits that have been pushed up to a public/shared branch! Only amend commits that only exist in your local copy or you're gonna have a bad time. You could also make the change as a new commit and then do rebase -i in order to squash them both together, but this is about a million times faster. and FML, I didn't put a space after an equals sign. This usually happens to me if I commit, then run tests/linters. # now your last commit contains that change! Mega hat tip to the many many many many many people who suggested adding it! Oh shit, I committed and immediately realized I need to make one small change! # make your change You can use this to get back stuff you accidentally deleted, or just to remove some stuff you tried that broke the repo, or to recover after a bad merge, or just to go back to a time when things actually worked. # each one has an index find the one before you broke everything # you will see a list of every thing you've Oh shit, I did something terribly wrong, please tell me git has a magic time machine!?! git reflog So here are some bad situations I've gotten myself into, and how I eventually got myself out of them in plain english. Git documentation has this chicken and egg problem where you can't search for how to get yourself out of a mess, unless you already know the name of the thing you need to know about in order to fix your problem. GitKraken GUI is free and available for Windows, MacOS and Linux! Click here to download GitKraken GUI.Git is hard: screwing up is easy, and figuring out how to fix your mistakes is fucking impossible. You should also only make resets to local commits that have not yet been pushed to a remote repo. And if you’ve accidentally made a hard reset but there were some things you wanted to keep - then you’re really in trouble. And all your resetted commit structure (which files and changes were associated to each commit),Ĭommit names etc are now lost in time and space in your repo. If you go forward with this, you’re probably now left withĪ whole lot of uncommited and unstaged changes. Imagine that you are trying to make a reset to a commit 20 commits behind the last one. In the examples above we have only resetted a single commit. Resetting can be a very destructive action if used improperly. The same thing goes for all the affectedĬhanges. Notice that all history after the “Added script.js” commit is now gone. This can really mess up your repo, so make sure to tread carefully The main difference is that the affected files now are unstaged.Ī hard reset is pretty much nuking the specified repo history. That you can either continue working on or discard.Ī mixed reset is pretty much the same thing as a soft reset. Script.js is now reset to it’s previous version, with a pending uncommited change There were 4 commits, nowĪll the changed files have also been uncommited and are now staged. I’ll explain the differences shortly.Īfter making a soft reset, notice that all commit(s) made after the commit we resetted to now are gone. In most scenarios you are fine with selecting Soft or Mixed depending on personal preference. Your choice will affect the state of the changes you are resetting. I am now given three options - Soft, Mixed or Hard reset. I start out by right clicking the commit I want to reset back to: I want to undo the last commit and go back in time to the previous commit, “Added script.js”, which I know contains the last working version The horror! But fear not, this is easily fixed. But only after I’ve made the last commit, I discover that I’ve accidentally I have for this demo created a repo with a few commits. Typo, bug etc that you want to edit or remove.Īnd in GitKraken this is of course only a few clicks away. Reset is a very neat feature in Git if you want to go back in time and make a change to one or several commits.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |