I'm starting to understand git but I'm still having some trouble with the abstraction. I checked out a previous version to make some changes with a simple:
git checkout [commit id]
And I got the message HEAD was moved to a new this new commit id. I made the changes that I needed and added and committed them. However, when I tried pushing the changes to Heroku I got the message that everything was up to date. I knew this couldn't be the case, so I assumed that I made some alternative branch when I went back to a previous version and committed changes.
So I then tried:
git merge master
Which errored when it tried to auto merge the files that I had been working on. So I cleaned up the conflicts that appeared in the file and added and committed the changes and did:
git merge master
This time however I got the message 'Already up-to-date.' When I tried pushing the changes to Heroku, the file was still in the state I left it when I jumped back a few versions. I'm not quite sure how to have the changes I made appear...
You are on a "detached HEAD". You're not on any branch, which makes a number of git operations difficult.
First thing to do is git checkout -b <new branch name>
. That way, at least, you'll have a name by which to refer to your current state.
Next we have to figure out what you were actually trying to do. You checked out a "previous version to make some changes"? What did you expect to do with those changes? You can't edit the past. (Well, you can, but it's highly unusual and you should ignore it for now.) You can add new stuff on top of a branch or you can make a new branch to hold an alternative version of the project.
In all probability, you should just have made your changes on the tip of master, committed them and then pushed them.
Or, if you want to make a branch, you should have done git checkout -b <new branch name> <id of commit to form base of new branch>
. Then, you could make changes, commit, and push the new branch with something like git push origin <new branch name>
. Making a branch would be for releasing a bug fix for an old version of your project. (Actually, depending on your workflow, you maybe should have branched in order to release that previous version and your bug fix would go on top of that pre-existing branch.)
I fear that the merging that you've done has left you in a state that will be difficult to recover from gracefully. If the changes you made were not big, you might just recreate them and toss your current state. Or, if you can find the commit with the changes, you might reset to master
and then cherry-pick it. You can use git whatchanged master..
to find that commit.
gitk --all
but even git log --graph --decorate --oneline --all
can suffice) to find the places you want to re-set various branches and so on, and then use git branch -f
to do the resets. Of course if you're not familiar with git, sometimes this is harder than just redoing the stuff you know how to do. :-) Anyway, for "git newbies", I find gitk --all
pretty instructive - torek 2012-04-05 02:24