I've been using git for one year and I'm able to use the common git commands, such as git add, git commit, git reset, git checkout, git rebase etc.
Today, I found something about git checkout that I can't explain.
As all we know, git checkout <branchname> can switch to the <branchname>. As my understanding, this command do the following things:
- switch branch pointer
- update the
HEADpointer - update the working zone and the index
In a word, this command does the three steps so that it can switch the branch.
And as all we know, git reset --soft can reset the HEAD pointer.
Now let me show you something "weird" to me.
git checkout br1
git reset --soft br2
git checkout br2
As my understanding about git checkout above, I thought that git reset --soft br2 was nonsense, which means that as my own opinion, the three commands are equivalent to git checkout br1 && git checkout br2.
However, after executing these three commands, I find that the last commit of br1 is brought to the branch br2, which means that the last commit of br1 has been copied to the current working zone and the current index.
Well, I'm confused now. I suddenly feel that the commands git checkout and git reset are kind of strange, I think I might have misunderstood the command git checkout for a long time...