开发者

How to restore the directory tree structure to a branch upon checkout to it

开发者 https://www.devze.com 2023-03-18 19:56 出处:网络
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

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 开发者_StackOverflowcommitting 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?


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


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


use this in branch A type

git stash

then switch branch

git checkout <branch name>

then

git stash pop

see if it works

0

精彩评论

暂无评论...
验证码 换一张
取 消