首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么无论我是否运行git add,当我切换分支(修改、添加、删除文件)时,git都会一直显示我的更改?

为什么无论我是否运行git add,当我切换分支(修改、添加、删除文件)时,git都会一直显示我的更改?
EN

Stack Overflow用户
提问于 2011-04-04 01:55:02
回答 2查看 47.2K关注 0票数 126

我是git的新手,我一直在尝试理解为什么git一直在显示我在另一个分支中的一个分支中所做的更改,当我运行git checkout在分支之间切换时,首先我试着不使用git add,但没有起作用。然而,我随后尝试使用git add,但没有解决这个问题。我还没有使用git commit。

这基本上就是我要做的:

代码语言:javascript
复制
$ git clone <a_repository>  
$ git branch  
* master  
$ git branch testing  
$ git checkout testing  
...edit a file, add a new one, delete...  
$ git status  
    # On branch testing  
    # Changed but not updated:  
    #   (use "git add/rm <file>..." to update what will be committed)  
    #   (use "git checkout -- <file>..." to discard changes in working directory)  
    #  
    #       deleted:    file1.txt  
    #  
    # Untracked files:  
    #   (use "git add <file>..." to include in what will be committed)  
    #  
    #       file2.txt  
no changes added to commit (use "git add" and/or "git commit -a")  
$ git branch  
  master  
* testing  
$ git checkout master  
D       file1.txt  
Switched to branch 'master'  
$ git status  
    # On branch master  
    # Changed but not updated:  
    #   (use "git add/rm <file>..." to update what will be committed)  
    #   (use "git checkout -- <file>..." to discard changes in working directory)  
    #  
    #       deleted:    file1.txt  
    #  
    # Untracked files:  
    #   (use "git add <file>..." to include in what will be committed)  
    #  
    #       file2.txt  
no changes added to commit (use "git add" and/or "git commit -a")  

我认为,当使用分支时,无论你在一个分支中做什么,它对所有其他分支都是不可见的。这不就是创建分支的原因吗?

我尝试使用"git add“,但更改在两个分支中都可见。在分支之间切换之前,我需要运行"git commit“来避免这种情况吗?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5531362

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档