I have a rails project and I did the following steps:
git commit -m "Format gemfile"
and git push
to make sure everything is clean. The id of this commit is b24d101
git checkout -b newbranch
While on the new branch I deleted a file, made changes to 2 other files and generated several other files.
git status
I have 2 files modified, 1 file deleted and several files untracked. So far so good.
I noticed a problem, so I moved back to the master branch via git checkout master
and deleted the newbranch via git branch -d newbranch
.
git status
still shows that there are several untracked files.
I decided to revert to my last commit.
git reset --hard b24d101
git status
now shows that no files are deleted or modified (and indeed I can confirm this after a manual check, the deleted file from step 3 is there, the edits on the 2 files from step 3 are gone). However I still have these several untracked files. I don't want them. Isn't git supposed to delete these files since they were created: a) on a new branch, which no longer exists and was not merged before deletion, and b) after the commit I reverted to?
P.S. Am I suppose to "clean" these files manually?
The files you generated on step 3 were never committed, so git didn't track them. Git never touches untracked files, that's why it left them on branch deletion. So it doesn't matter that "they were created on a new branch", since you didn't add or track them when you were on the branch.
However if you'd have committed them they would have been correctly deleted as soon as you'd have switched back to master
branch.