![]() With Git, revert has a very specific meaning: create a commit with the reverse patch to cancel it out. In that case, you could indeed revert the commits. On the other hand, if you've published the work, you probably don't want to reset the branch, since that's effectively rewriting history. If you mess up, you've already thrown away your local changes, but you can at least get back to where you were before by resetting again. # You could get merge conflicts, if you've modified things which were # This saves the modifications, then reapplies that patch after resetting. # Alternatively, if there's work to keep: # Don't do it if you have uncommitted work you want to keep. One, if you haven't published any of these commits, simply reset: # This will destroy any local modifications. If, on the other hand, you want to really get rid of everything you've done since then, there are two possibilities. You could reset to throw them away you could stash, checkout, stash pop to take them with you you could commit them to a branch there if you want a branch there.) Hard delete unpublished commits (If you've made changes, as always when switching branches, you'll have to deal with them as appropriate. To go back to where you were, just check out the branch you were on again. ![]() Or if you want to make commits while you're there, go ahead and make a new branch while you're at it: git checkout -b old-state 0d1d7fc32 If you want to temporarily go back to it, fool around, then come back to where you are, all you have to do is check out the desired commit: # This will detach your HEAD, that is, leave you with no branch checked out: The main thing is to understand the difference between revert and reset.This depends a lot on what you mean by "revert". Now for the GUI question you had, you can prob right click on the commit you want to get back to ( reset) or remove the changes that one commit made ( revert) by right clicking a commit in the history tree or maybe theres a button to do it. this is DANGEROUS operation so be careful if you use it, you can change the state for other users of the repo. you are changing the history of the project => when you perform git push you need to use the -force/ -f flag. reset: you will move the state of your repository history back in time and possibly lose all the changes that were made on top of that.you have not changed the history of the project but added to it => when you perform git push all is good this means you create a new node in the commit tree, i.e. revert: creates a new commit which is basically the opposite diff of the one created by the commit you are reverting (you'll see it in the automatic commit message).Regarding the part where you asked to get back to a older state there are 2 ways: That is the way git keeps track of your changes (and you can check it with the log command, or in the GUI tree view of the history, not sure how its called since i dont use GUI for git) git folder in the repository and assigns a hash to that change. To answer your 1st question: after you run the commit command the file gets saved on your hard disk a s a normal file, but git also saves the diff of the change in the. Make sure you only use it to get rid of commits that haven't been pushed to another repository! ![]() This can cause some serious headaches if any of those lost commits have been pushed to a public repository. Ī note of warning that git reset will alter history - if I made several commits and then reset to the first commit, the subsequent commits will no longer be in the commit history. ![]() With the -hard option, it replaces the contents of your working directory with what was on. If you want to set your branch to the state of a particular commit (as implied by the OP), you can use git reset, or git reset -hard The first option only updates the INDEX, leaving files in your working directory unchanged as if you had made the edits but not yet committed them. It's more or less a way to 'undo' a commit and save that undo in your history as a new commit. The above answer is not quite correct - git revert does not set your repository to that commit - git revert creates a new commit that undoes the changes introduced by commit.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |