[英]Whenever I create a new branch it shows all files stored in master branch that it should be empty
user@LAPTOP-LNQB4U6E MINGW64 ~/store (master)
$ git branch
* master
user@LAPTOP-LNQB4U6E MINGW64 ~/store (master)
$ ls -l
total 0
-rw-r--r-- 1 user 197121 0 Jun 12 10:43 file1.py
user@LAPTOP-LNQB4U6E MINGW64 ~/store (master)
$ git branch part1
user@LAPTOP-LNQB4U6E MINGW64 ~/store (master)
$ git checkout part1
Switched to branch 'part1'
user@LAPTOP-LNQB4U6E MINGW64 ~/store (part1)
$ git branch
master
* part1
user@LAPTOP-LNQB4U6E MINGW64 ~/store (part1)
$ ls -l
total 0
-rw-r--r-- 1 user 197121 0 Jun 12 10:43 file1.py
user@LAPTOP-LNQB4U6E MINGW64 ~/store (master)
$ git branch
* master
user@LAPTOP-LNQB4U6E MINGW64 ~/store (master)
$ ls -l
total 0
-rw-r--r-- 1 user 197121 0 Jun 12 10:43 file1.py
user@LAPTOP-LNQB4U6E MINGW64 ~/store (master)
$ git branch part1
user@LAPTOP-LNQB4U6E MINGW64 ~/store (master)
$ git checkout part1
Switched to branch 'part1'
user@LAPTOP-LNQB4U6E MINGW64 ~/store (part1)
$ git branch
master
* part1
user@LAPTOP-LNQB4U6E MINGW64 ~/store (part1)
$ ls -l
total 0
-rw-r--r-- 1 user 197121 0 Jun 12 10:43 file1.py
That seems expected:这似乎是意料之中的:
either file1.py
was not tracked (added/commited) to the master branch, and that private file would not disappear just because you are creating a branch要么file1.py
没有被跟踪(添加/提交)到主分支,并且该私有文件不会仅仅因为您正在创建一个分支而消失
or file1.py
was part of the master branch, and creating a new branch from there would start with the master branch content.或file1.py
是 master 分支的一部分,从那里创建一个新分支将从 master 分支内容开始。
Only creating an orphan branch ( git switch --orphan
) would start with an empty content.只有创建孤立分支( git switch --orphan
)才会以空内容开始。
Note: if you are using Git 2.23 or more recent, use git switch
, not the confusing git checkout
old command .注意:如果您使用的是 Git 2.23 或更高版本,请使用git switch
,而不是令人困惑的git checkout
old command 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.