Git分支切换不会更改代码文件夹文件 [英] Git branch switching does not change code folder files

查看:957
本文介绍了Git分支切换不会更改代码文件夹文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对这个问题的后续行动.

我使用git clone git@git.mytest.com:TEST命令克隆了远程主项目文件夹.从Git根目录开始,我执行了cd Test命令将其移入该文件夹.然后,我使用git checkout -b myBranch创建了一个分支.现在在git bash上显示我在新分支中.我在测试"文件夹中创建了一个test.txt文件,然后将分支切换为主".我仍然看到文本文件. Git不应显示test.txt,因为它不是master的一部分.如果必须这样做,是否需要在分支中提交我的更改.

I cloned the remote master project folder using git clone git@git.mytest.com:TEST command. from the Git root, I did a cd Test command to move into that folder. I then created a branch using git checkout -b myBranch. Now on the git bash it shows that i'm in the new branch. I created a test.txt file in the Test folder and then switched my branch to master. I still see the text file. Isn't Git supposed to not show the test.txt since it not part of master. Do I need to commit my changes in the branch if this has to happen.

我以为最初可能发生这种情况,因为它不是我的.net项目的一部分(我在master和branch中).但是,当我尝试将文件添加到mybranch时,也发生了同样的情况.切换母版后,仍然可以在fie系统中看到文件夹的更改图标.

I thought initially this may have happened because it is not part of my .net project (that I have in the master and branch). But the same happened when I tried to add a file to mybranch. When I switch my master, I still see the changed icon for the folders in the fie system.

我想念什么?感谢您的所有帮助,因为我已经花了很多时间尝试找出Git.每次我认为掌握了它,总会发现一些东西.

What am I missing? Thank you for all your help as I have spent a lot of time trying to figure out Git now. Every time I think I have got it, there is always something.

推荐答案

不,它也不属于master分支,但也不属于myBranch.它是未跟踪的,因为您从未提交过该文件.运行git status,您会看到它被列为未跟踪.由于从未进行过登台或提交,因此Git不会(也无法)管理其存在,因此无论如何它都将停留在该位置.

No it's not part of your master branch, but it's not part of myBranch either. It is untracked, because you never committed the file. Running git status you'll see it listed as untracked. Since it was never staged or committed, Git doesn't (and can't) manage its existence, so it stays there regardless.

此外,如果可以的话,修改后的文件仍保留在分支之间.当在肮脏的工作树上切换分支时,Else Git会给您一个错误.再次,这是因为Git没有这些更改的内部副本,所以它们仅存在于您的文件系统中,直到提交后才存在于Git中.

Further, modified files remain between branches if they can. Else Git will give you an error when switching branches about a dirty working tree. This is, again, because Git has no internal copy of those changes, they exist only in your filesystem, and not within Git till they are committed.

这篇关于Git分支切换不会更改代码文件夹文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆