I replied to Howard directly without CCing the Git ML (as a mistake) anyway he solved the problem on his own now. this was my first reply that didn't reached the list On Tue, Sep 15, 2009 at 12:31 PM, Howard Miller <howard@xxxxxxxxxxxxxxxxxxx> wrote: > I had made some changes to some files and then done a commit. Only > then did I realise that I had the wrong branch checked out. To make > matters worse I then did a 'git reset HEAD^' which means that I can > now no longer switch branches. I am stuck. I had some advice (thanks!) > but it was not complete. I'd appreciate some more help. I think that explaining what you did and what happened along your modification will help you to understand. It's not that hard, really :) so this are the steps you followed (confirmed by your reply to Martin) 1 - you were on branch X, thinking your were on branch Y Branch X point to a commit which is the last commit of branch X: you can visualize the situation like this BRANCH Y | c1 - c2 - c3 - c5 \ c4 - c6 | BRANCH X (and your current HEAD) the cN stuffs are commits BranchX, BranchY and HEAD are only pointers to a commit 2 - you worked on on branch X modified some files/added new one/whatever now you may have some untracked files (new files) and some untracked modification (modified files) untracked means that those files/modification aren't in the git repository, they are not indexed 3 - git add . You ask git to index the modification to prepare a commit: we say that files are "staged" At this time HEAD and BRANCH X are still on c6 commit (see graphic above) 4 - git commit Ok what happen here? BRANCH Y | c1 - c2 - c3 - c5 \ c4 - c6 - c7 | BRANCH X (and your current HEAD) you created a new commit and moved the 2 pointers. 6 - you realized the mistake now what you want here is to make your Branch X point again the c6 commit and, probably, save your modification for c7 but you actually panicked :) and you did: 5 - git reset HEAD^ Let's see what happen to the index: BRANCH Y | c1 - c2 - c3 - c5 \ c4 - c6 -c7 | BRANCH X (and your current HEAD) seems right uh? no you have a lot of untracked files in your directory that's because git reset doesn't change your directory content it only work on indexes. So what you now have in your project directory is what you did on the top of your initial Branch X try a gitk --all it should show you that Now you have 2 options: 1) discard what you did for the wrong commit c7 (and restart again on branch Y) 2) try to backup your work and migrate it to branch Y the 1) is the easiest one: just execute git reset HEAD --hard the option --hard ask git to give you a "clean" reset modifying your working directory to be exactly like the indexed c6 commit. then checkout branch Y: git checkout Y and restart to work on that branch if you want to recover what you did to avoid re-doing it then the things became a little harder but not that much :) there are many way to do it because git gave you a lot of tools we can help if you calm down :) for now: question about this? regards, Daniele -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html