Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git,为什么我的主分支会受到影响?_Git - Fatal编程技术网

Git,为什么我的主分支会受到影响?

Git,为什么我的主分支会受到影响?,git,Git,我在一家总店工作。我有了一个新的想法,所以我选择了: git checkout -b new_branch_name 对新分支做了一些更改,然后切换回主分支。我对新分支所做的所有更改都应用于master。我该怎么做才能防止这种情况发生呢?因为您没有添加或提交新文件,它们未被跟踪,不在您的git repo范围内。它们只存在于文件系统上。您可以使用git clean-f-d删除它们,以恢复回购的干净状态。当您不向新分支提交更改时,更改将被缓存,并可通过父分支访问(master) 为了防止这种情况,

我在一家总店工作。我有了一个新的想法,所以我选择了:

git checkout -b new_branch_name

对新分支做了一些更改,然后切换回主分支。我对新分支所做的所有更改都应用于master。我该怎么做才能防止这种情况发生呢?

因为您没有
添加
提交
新文件,它们未被跟踪,不在您的git repo范围内。它们只存在于文件系统上。您可以使用
git clean-f-d
删除它们,以恢复回购的干净状态。

当您不向新分支提交更改时,更改将被缓存,并可通过父分支访问(
master

为了防止这种情况,在切换到父分支之前,您应该始终
git add[FILE]
git commit

如果您在提交之前切换,只需切换回新分支,添加更改的文件并提交(如果您没有添加或提交任何内容):

# switch to your new branch
git checkout new_branch_name

# confirm that your changes are still there :
git status

# commit on your new branch
git add ...
git commit ...

# go back to master
git checkout master

听起来不太可能。您是如何切换回
master
分支的?另外,您是否确实添加了更改?只有跟踪的文件才会在git签出时更改。这是git新用户的常见误解。未提交的更改不属于任何分支。切换分支时,如果工作树和暂存文件中的更改与新分支引入的更改不冲突,Git将保留这些更改。使用
Git checkout master
切换回。我没有在任何一个分支上添加
提交
。所以,我应该做的是,在master上提交
更改?那么它会不会不受任何新分支的影响?我在一个新分支上所做的实际上是无用的,并且希望它被删除。如果你有一个新想法,你可能想
git commit
或者
git stash
本地更改以备以后使用,或者
git reset
或者
git clean
放弃当前的工作。这真的取决于你。