3

In my rails project i use git to manage my code. I delete a branch with git like this :

git branch -D "my-branch-with-errors"

but files added with this removed branch still exists in my project. what's the problem here and how can i solve this issue. thank you

medBouzid
  • 7,484
  • 10
  • 56
  • 86
  • What did you expect? Branches are just "pointers" to commits. Commits are what index/store files. – Robert Rouhani Aug 03 '13 at 18:09
  • i remove this branch because i added lot of files by error in this branch, and i expect these files to be removed but they still exist in my project !!! – medBouzid Aug 03 '13 at 18:13

1 Answers1

2

If you create new files in a Git repository but don't git commit them, Git doesn't manage them. This means that changing branches, changing commits, or reverting changes does not affect those new files. You can either manually delete those new files, or run git clean, which deletes unversioned files.

To delete the files you added, run

git clean -n

This will let you see which files Git will delete before your remove them so that you can be sure it won't affect any files you want to keep. Once you are sure that it will only affect files you want to get rid of, run

git clean -f -d

For more information, see this question.

Community
  • 1
  • 1
Kevin
  • 14,655
  • 24
  • 74
  • 124
  • I was bitten by this behavior myself a couple weeks ago. This is a question I asked about it: http://stackoverflow.com/questions/17793977/error-message-nameerror-at-users-sign-in-undefined-local-variable-or-method-r – Kevin Aug 03 '13 at 18:33
  • yes i don't commit these file, i just delete the branch, and i expect that any file created in this branch will be removed automatically :( so are you sure there is no way to solve this ! for example return to the last good state in previous branch ... ? – medBouzid Aug 03 '13 at 18:36
  • Actually, a quick Google search suggests that `git clean` might be what you're looking for. Let me read about it a bit and then edit my answer... – Kevin Aug 03 '13 at 18:38
  • it says that git-clean - Remove untracked files from the working tree ? – medBouzid Aug 03 '13 at 18:41
  • Yep. The files you've added haven't been "recorded" by git because you haven't committed them. The technical term for those files is "untracked files." – Kevin Aug 03 '13 at 18:44