且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

git如何在不提交更改的情况下切换分支

更新时间:2022-05-12 02:06:45

我正在使用 git 1.9.1 ,并且可以通过更改文件来切换分***已经在树中,然后用 git update-index --skip-worktree filename 跳过。

I'm using git 1.9.1 and it is possible to switch branches with changes in a file that's already in the tree and then skipped with git update-index --skip-worktree filename.

文件切换后未更改(即未更改为我切换到的分支中的版本)。

The file is not changed after the switch (i.e. it is not changed to the version in the branch I switched to).

(我应该以为这是自1.7.7版本以来的行为,因为其发行说明指出了 * git stash --include-untracked选项。,但在您问问题之前发布了1.7.7,所以我不知道。)

(I would have thought that this is the behavior since 1.7.7 since its release notes state * "git stash" learned an "--include-untracked option". but 1.7.7 was released before you asked the question, so I don't know.)

请注意,当尝试切换到没有文件的分支时,git仍然会抱怨

Please note that when trying to switch to a branch that doesn't have the file git still complains with


错误:您对以下文件的本地更改将被结帐覆盖:
f1.config

error: Your local changes to the following files would be overwritten by checkout: f1.config