Reputation: 1143
I'm trying to use Git for a personal project just for the sake of getting used to it but I got into a situation I don't know how to tidy up...
I don't remember how it happened, I think I tried to roll back to some commit but now my git is a mess. I tried other things which I don't really know what they are and this I shouldn't have.
Here is a screen of how it looks like:
I just would like to go back to the selected commit ("With each new wave, the game...").
I'm sure this is really simple but I got lost with all those branches and stuff. So if someone could tell me how to get back to this, not only for my working copy but also on the server, that would be nice.
Thanks :-)
Upvotes: 1
Views: 1011
Reputation: 387667
Looking at that history, it seems that you commited that commit, cherry-picked it on another branch, and then tried to revert it on both branches again.
To clean that up I would first suggest you to make sure that all those commits (especially including those uncommitted changes at the top) don’t contain any information you don’t want to lose.
Afterwards, you can use the following command to throw everything else away and just get back to that one commit. Note that this really cuts of the tree, hence make sure that you don’t have any data you want to keep.
git reset --hard 8791cc9176
This will reset your current branch to that commit, ignoring everything else. So you probably want to reset your local master there. Afterwards, you can delete your Safe
branch using git branch -D Safe
(note the upper-case D
to be able to delete branches that are not merged into other branches—for all other cases, use a lower case d
to make sure you don’t lose information).
Since your remote is also on a more advanced state, you probably want to get rid of those extra commits there too. Note that by default you cannot just push an older history and replace this on the remote. Instead you have to force-push it using git push --force origin master
(or -f
in short). While it is okay to use it for your personal project, you should know that you should never do this when working with others or when your repository is publicly available. This will change the history on the remote to a state that cannot be automatically handled with by other users accessing the remote. So they will likely run into conflicts. That’s why you should (a) always make sure that what you are pushing is really good-to-push, and (b) always undo things on the remote by adding commits (e.g. reverting commits as you have already used here).
Upvotes: 2
Reputation: 2036
In the disordered state of your repository, you use git checkout --detach <commit>
to go to any commit. For example, git checkout --detach 8791cc9
takes you to the "With each new wave, the game..." commit. git checkout
is mostly used to go from the tip of one branch to another, but the --detach
is useful to checkout any commit.
If you need to make any modifications to that commit, you will need to create a branch out of it: git checkout -b new_branch <commit>
.
More information in the git-checkout manpage.
Upvotes: 0