1

This should be a basic misunderstanding.

I'd like to work on a few features separately, and be able to jump from one to another at any given time. But I running into a problem. This is what I do:

I start from a local 'develop' branch, and create a new local feature branch 'A'. I do some work there - let's say I add a new file 'file A', commit the local changes with commit message 'commit A' and push them to a remote branch on github for code review.

While I wait for the code review to complete, I want to start working on a another feature 'B', which is unrelated to 'A' and doesn't depend on it.

So I check out 'develop' in order to create branch 'B' from it. While on 'develop' I type 'git log' and see that 'commit A' isn't there (what I expect). But when I browse the file system I see 'file A'! and obviously when I create branch 'B' from 'develop' file 'A' is there on branch 'B'. I don't want that. I want to work on a clean branch that has no code changes from another local branch.

What am I missing?

Legato
  • 1,031
  • 1
  • 9
  • 20
  • Does your .gitignore file have an entry that matches 'File A' by any chance? Maybe the file is being ignored in your feature branch, but not your 'develop' branch. – Greg Burghardt Mar 25 '15 at 12:22
  • Thank you. That's interesting... in reality it isn't a actual single file that was added, but a bunch of new directories with new source files in them. When I switched to develop I saw that the directories are still there. But now given your pointer I notice that they are empty... hmm. So the new files aren't there but the new directories are. The directory names aren't included in the .gitignore. Are directories treated in some special way in git? – Legato Mar 25 '15 at 12:34
  • Where are you checking the files. sometimes IDE's like eclipse needs you to refresh to see the changes. – Vishwanath Mar 25 '15 at 12:45
  • 1
    Git operates on file contents, not file names. Empty directories are ignored by Git. – Greg Burghardt Mar 25 '15 at 12:53
  • I use intellij for editing but do all git related stuff on the command line. Per my response to @GregBurghardt above, I found out that these are only new directories that stick around, and not actual files. I verified from both intellij (after refreshing) and the terminal – Legato Mar 25 '15 at 12:54
  • @GregBurghardt. That's good to know. So is the behavior I'm seeing expected? empty directories "float" from one feature branch to another (on disk)? (while being untracked by git) – Legato Mar 25 '15 at 12:57
  • 1
    @Legato: Yes, this is intended behavior. See [Git checkout/pull doesn't remove directories?](http://stackoverflow.com/questions/1499157/git-checkout-pull-doesnt-remove-directories) for a related question. See the [Git Documentation](http://git-scm.com/docs/gittutorial#_git_tracks_content_not_files). – Greg Burghardt Mar 25 '15 at 13:03

0 Answers0