1

我试着做一个git branch testbranch,在这个结帐之后git checkout testbranch。然后我编辑了一个文件,例如“README”。

现在我试图切换回“master”分支,它总是会产生一个merge而不是只抱怨我有未提交的文件。

那么这是为什么呢?我以为我会得到一个错误,比如......

错误:您对“X”进行了本地更改;不能切换分支。

这么久,谢谢你所有的鱼。

4

2 回答 2

0

this issue occurs on me.

Actually, it's not a big deal.

Condition 1: git give you an error:

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

Condition 2: git gives you this:

M       README
Switched to branch 'master'

But, when does Condition 1 occur? or Condition 2?

Condition 1: there is a conflict of changing in README between master branch and testbranch.

Condition 2: it's ok for changing of README in master branch, so the changing occurs in master branch.

So no matter whether it is Condition 1 or 2, it's ok for you to use git because git is smart.

That's my point, i know you got it.

Good luck.

于 2012-10-10T16:39:26.840 回答
0

如果您的更改兼容(快进),git 不会抱怨并会保留修改后的版本。Git 只会假设您在错误的分支上编辑了文件,并想回到正确的分支。

不过,这不是合并:如果文件都被修改,git 将遵守。

合并只能在提交级别完成,而不是在文件级别。

于 2012-10-10T14:52:57.520 回答