Question

I have a rails project and I did the following steps:

  1. git commit -m "Format gemfile" and git push to make sure everything is clean. The id of this commit is b24d101

  2. git checkout -b newbranch

  3. While on the new branch I deleted a file, made changes to 2 other files and generated several other files.

  4. git status I have 2 files modified, 1 file deleted and several files untracked. So far so good.

  5. 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.

  6. git status still shows that there are several untracked files.

  7. I decided to revert to my last commit.

  8. git reset --hard b24d101

  9. 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?

Was it helpful?

Solution

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.

OTHER TIPS

I think this the answer to the "P.S." question is Yes. As long as new files are not staged or committed, they don't 'belong' to any branch and git completely ignore them, and if you want to delete them, you will have to do it manually.

Regards, Udi

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top