在新克隆的git仓库中,我无法结账到新的分行

时间:2016-07-02 00:54:43

标签: git linux-kernel

我刚刚克隆了linux内核代码,然后当我尝试结帐到新分支时,我发现它因本地更改而失败。

我很困惑为什么新克隆的代码可以进行所谓的本地更改? 最后,我使用“git checkout -f -b xxx”以强制方式检查新分支以丢弃本地更改,但我仍然想知道是否有优雅的方式来成功结账而非强制结束?

$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
Cloning into 'linux-stable'...
remote: Counting objects: 5253622, done.
remote: Compressing objects: 100% (1189462/1189462), done.
remote: Total 5253622 (delta 4399195), reused 4796362 (delta 4030229)
Receiving objects: 100% (5253622/5253622), 1005.30 MiB | 576.00 KiB/s, done.
Resolving deltas: 100% (4399195/4399195), done.
Checking connectivity... done.
Checking out files: 100% (54401/54401), done.

$cd linux-stable

$ git checkout -b linux-4.2.y origin/linux-4.2.y
error: Your local changes to the following files would be overwritten by checkout:
        include/uapi/linux/netfilter/xt_RATEEST.h
        net/netfilter/xt_TCPMSS.c
Please, commit your changes or stash them before you can switch branches.
Aborting


$ git checkout -f -b linux-4.2.y origin/linux-4.2.y
Checking out files: 100% (28688/28688), done.
Branch linux-4.2.y set up to track remote branch linux-4.2.y from origin.
Switched to a new branch 'linux-4.2.y'

1 个答案:

答案 0 :(得分:1)

在我看来,一个无关的过程正在影响您工作目录的更改。

为避免这种复杂情况,请专门克隆到目标分支:

git clone \
-b linux-4.2.y \
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git