git - 忽略提交的文件和切换分支

时间:2013-04-03 14:38:15

标签: git

我有本地仓库和远程,说“上游”。在远程仓库中,一些基本的配置说“file1.txt”和“file2.txt”,我将更改拉到分支“some_branch”,然后输入:

git update-index --assume-unchanged file1.txt
git update-index --assume-unchanged file2.txt

允许修改此文件,使用我本地更改添加一些更改,我不想提交。

之后在“上游”增加了分支“somefeature”

fetch upstream somefeature:somefeature

并尝试:

$git checkout somefeature
error: Your local changes to the following files would be overwritten by checkout:
    file1.txt
    file2.txt
Please, commit your changes or stash them before you can switch branches.
Aborting

$git checkout -f somefeature 
error: Entry 'file1.txt' not uptodate. Cannot merge.

然后我尝试:

$git stash 
No local changes to save

$git stash -u
No local changes to save

$git update-index --no-assume-unchanged .
Ignoring path 

我也试过“--skip-worktree”,但也没有成功。

那么,如何使用“add”或“commit -a”跳过本地更改,但是能够更改分支,并将这些隐藏的更改应用于不是从当前创建的其他分支?

1 个答案:

答案 0 :(得分:1)

要藏匿一切,请尝试:

git stash save --all --no-keep-index