1

Suppose i have branch master in the master i created one.c, then committed the changes

then i created another branch called new_branch, and checked into it then added two.c, then committing the changes

when i checkout to master again, two.c is still present in the working directory

i need a way by which, upon checkout a specific branch, the directory tree goes bach to what it was

in my case , upon switch to master , i want not to see two.c in the currect directory and if i checkout new_branch , two.c appears again

How this can be done?

manojlds
  • 290,304
  • 63
  • 469
  • 417
Joe
  • 11
  • 1
  • 1
    No need to add `Git:` to your question and also start with "this is a git question" That is what tags are for. – manojlds Jul 08 '11 at 17:56

3 Answers3

0

git reset --hard should remove untracked files (like two.c)

Jim Deville
  • 10,632
  • 1
  • 37
  • 47
  • reset --hard will permanently remove the file, i want to hide it from my working directory while in master and show it back if i checkout to new_branch – Joe Jul 08 '11 at 17:36
  • reset doesn't affect committed changes. It will delete the file in master, but it will also restore the file in the branch – Jim Deville Jul 08 '11 at 17:39
  • then how to restore it , after git checkout new_branch? how to make it show up again? – Joe Jul 08 '11 at 17:47
  • git reset --hard again. That said, something is wonky. When i make a temp repro and try to reproduce your situation, git checkout master and git checkout new_branch automatically modifies the working directory to match the correct branch – Jim Deville Jul 08 '11 at 17:51
  • no, they do not modify current directory.... when i switch to master , two.c is still there... if i used reset --hard on master and switched to new_branch it is never shown again in new_branch as it should, it is deleted forever – Joe Jul 08 '11 at 17:59
0

What you expect is the actual normal Git behaviour. When you switch to a branch, the files not in the branch from the previous branch are "hidden." But it is known that sometimes that is not the case. Usually that occurs when the file ( in your case two.c ) is in use, say in an IDE.

Have a look here: Git not removing files when switching branch and here: git checkout remote branch shows extraneous files?

Like the answers linked above suggest, try git reset --hard and git clean -fdx

Community
  • 1
  • 1
manojlds
  • 290,304
  • 63
  • 469
  • 417
0

use this in branch A type

git stash

then switch branch

git checkout <branch name>

then

git stash pop

see if it works

TheOneTeam
  • 25,806
  • 45
  • 116
  • 158