I've just made a commit in my project, and I was creating a tag in every step, but it seems the last commit was done in some of this tags. The thing is that I can not longer see my latest change from a minutes ago. How can I checkout in my last commit no mater what tags are in my project? I need the last one. Any help?
This is what I was doing:
- Coding a simple login module at 60%
- Making commit for the 60% of login module (after git add -A)
git commit -m "login module to 60%"
- Finishing coding login module at 100%
- Creating a tag with: git tag -a myTag-01 -m "Login module finished"
- And so on...
Best How To :
Simply checkout the name of the branch for which you need the last commit. So if you are working on
git checkout master.
(Edit: after getting more illumination of the problem from the comments, it is not as easy as above).
OK, so my guess is that you committed while in a detached HEAD state. What this means is that you were not really on a branch when you committed, so there is nothing pointing to your last commit; you need to find it. Do this by doing a
git reflog. This will show you, among other things, your recent commits. Find the one closest to the top that looks like a commit (i.e. one that has a commit message). The hash will be listed next to it; use that to do a
git checkout <hash>.
So now you that you are on your commit, you have a few choices. What you should do is create a branch that points to that commit with
git checkout -b branch-name. An alternative would be to just tag it, like it seems you have been doing. The advantage of making a new branch is that every time you commit on that branch, the branch will be advanced to that commit, so you don't run into these kinds of problems again.
Also, I would strongly recommend you give the Git book a solid read. It will make your life a whole lot easier going forward.
By the way, if you really tagged your last commit, you can list all the tags with
git tag -l, and get the hash that way as well. In fact, once you know the tag name, you can just
git checkout <tag-name>.