Git branch not working the way I expected it to
In my project master branch I commit changes: git commit -a
create & switch to new branch: g开发者_StackOverflowit checkout -b newbranch
try some stuff...
realize 'stuff' didn't work out the way I thought it might so switch back to master: git checkout master
with intent of moving along from there... but realize some files added in newbranch are still in TextMate... so...
I type git status
I still see all the stuff I thought I'd left in newbranch is listed under "Untracked files"
I try: git reset --hard
to take me back to that last commit..but changes in newbranch still persist?!?
what am I missing?
What are you missing? Well, the files in questions are untracked and git wouldn't touch those with a ten-foot pole. ;)
In all honestly, if you weren't going to commit anything there was probably no reason to checkout a new branch.
You could have tried the new changes as normal. If you didn't like what you saw but wanted to use the new code later, you could have stashed it, like so:
git stash save "Some changes that didn't work out."
If you absolutely wanted it gone instead, all you had to do was:
git clean -d --dry-run
and then when sure:
git clean -df
If certain files are untracked, then git won't do anything to those files.
since you have untracked files (I'm assuming you did not commit them) you have a dirty working directory. If you want to zap those as well, you can use the clean command:
git clean -df
The d modifier specifies that you would like to act upon untracked directories as well. The f modifier specifies force. Clean will not remove things if you don't specify this parameter by default. You could add the x modifier in case you would want to delete ignored files as well, but I would not recommend that.
From the symptoms described it seems that you may have untracked files. Untracked files will remain when switching branches.
To clear untracked files
git clean -dfx
To reset changed files to the head of the branch you are currently on
git reset --hard
精彩评论