适用于Windows 2.5.2的Git.我希望如果索引具有未更改的更改,那么Git将禁用对其他分支的检查.但我看到其他结果.样本脚本:
#!/bin/bash
# script.sh
# Run this script in the Git Bash.
git --version
host="./sandbox"
if [ -d $host ]; then
rm -r $host
mkdir $host
echo \"$host\" directory recreated...
else
mkdir $host
echo $host directory \"$host\" created.
fi
cd $host
git init -q
touch 1.txt 2.txt 3.txt
git add "*"
git commit -qm "Initializing"
git branch
ls
git checkout -qb branch#1
rm 3.txt
echo ABCD >> 1.txt
# git commit -aqm "branch#1_commit#1"
git branch
ls
git checkout -q master
git branch
ls
git checkout -qb branch#2
rm 2.txt
echo 1234 >> 1.txt
# git commit -aqm "branch#2_commit#1"
git branch
ls
git checkout -q master
git branch
ls
Run Code Online (Sandbox Code Playgroud)
我有这样的输出:
bushm@DESKTOP-ISD2NUH MINGW64 /d/src
$ /d/src/script.sh
git version 2.5.0.windows.1
./sandbox directory "./sandbox" created.
* master
1.txt 2.txt 3.txt
* branch#1
master
1.txt 2.txt
branch#1
* master
1.txt 2.txt
branch#1
* branch#2
master
1.txt
branch#1
branch#2
* master
1.txt
bushm@DESKTOP-ISD2NUH MINGW64 /d/src
$
Run Code Online (Sandbox Code Playgroud)
我看到切换完成但切换后工作树是相同的(一个文件而不是三个)(未更新).我希望在切换索引之后,它的内容将被取消,并且分支的最后一次提交将被提取到工作树中.为什么工作树没有根据master分支的最后一次提交的内容更新?
小智 6
我希望如果索引具有未更改的更改,那么Git将禁用对其他分支的检查.
这种期望是错误的.您可以期待的是,如果切换到不同的分支可能会导致您丢失数据,那么Git将阻止您切换到该不同的分支(除非您强制它).但在您的情况下,切换到不同的分支不会对您造成任何伤害.您对某些文件进行了本地更改,但这些文件在所有分支中都是相同的,因此可以简单地保留本地更改.