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
这似乎是预期的:
file1.py
都没有被跟踪(添加/提交到主分支),并且该私有文件不会仅仅因为您正在创建分支而消失
或file1.py
是master分支的一部分,从那里创建一个新分支将从master分支的内容开始。
[仅创建孤立分支(git switch --orphan
)会以空内容开头。
注意:如果您使用的是Git 2.23或更高版本,请使用git switch --orphan
,而不是git switch
。