gitgit-clean

remove untracked file but not delete it from hard disk


In my branch A, I created a new directory myDir. I commited all changes on that branch by git add . and commit. I don't see any untracked file or directory.

Then I switch to branch B, I see untracked file myDir.

How can I remove myDir from branch B but still have it when switch to branch A ? I mean I don't want to really delete myDir from hard disk and I don't want to see untracked file myDir either on branches (other than branch A) .

I know there is git clean command, but it deletes files from hard disk, right?


Solution

  • There is no real problem removing myDir from your disk, when you will switch back to branch A, myDir will appear again.

    So you can safely use git clean (in this case, since you already committed myDir on another branch).