Git新文件出现在所有分支中 [英] Git new file appears in all branches

查看:120
本文介绍了Git新文件出现在所有分支中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为在一个分支上创建的文件不会出现在其他分支中,直到我合并或重新分支分支为止。



我有两个分行:
$ b


  1. master

  2. new_contact_page

我检出 new_contact_page 分支。

  $ git checkout new_contact_page 

然后我创建一个新文件。

  $ vi contact_page.html 

没有执行任何Git命令,我切换回 Master 分支。

  $ git checkout master 

然后我看到这个contact_page.html文件也在我的 Master 分支中。

  $ ls(contact_page.html显示在列表中! )

不应该只存在于 new_contact_page 分支中吗?

解决方案

Git永远不会触及任何实际不在您的资源库中的文件。 (未跟踪的文件)



您需要 git add git commit

I thought a file created on one branch will not appear in any other branches until I merge or rebase the branch?

Example:

I have two branches:

  1. master
  2. new_contact_page

I checkout the new_contact_page branch.

$ git checkout new_contact_page

Then I create a new file.

$ vi contact_page.html

Without doing any Git commands, I switch back to my Master branch.

$ git checkout master

Then I see that this contact_page.html file is also in my Master branch.

$ ls   (contact_page.html shows up in the list!)

Shouldn't the file only exist in new_contact_page branch?

解决方案

Git will never touch any files that aren't actually in your repository. (untracked files)

You need to git add and git commit the file (into one branch) first.

这篇关于Git新文件出现在所有分支中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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