我在Git中看到一种对我来说非常神秘的行为。
我保留了Github的Linux存储库的克隆,以便在本地使用Git。为了清楚起见,我在这个存储库中做的不多:我获取更改,更新master
,签出特定版本,有时我会尝试使用Git GUI来查看大型项目中的可视化效果。
TLDR版本:我从未对其中的文件进行任何更改。
今天早些时候,我签出了master
并从Github取消了更改。一切似乎都没事。但我怀疑它实际上没有。这就是git status
现在的样子。
axel@macbook ~/Depots/linux $ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: include/linux/netfilter/xt_connmark.h
# modified: include/linux/netfilter/xt_dscp.h
# modified: include/linux/netfilter/xt_mark.h
# modified: include/linux/netfilter/xt_rateest.h
# modified: include/linux/netfilter/xt_tcpmss.h
# modified: include/linux/netfilter_ipv4/ipt_ecn.h
# modified: include/linux/netfilter_ipv4/ipt_ttl.h
# modified: include/linux/netfilter_ipv6/ip6t_hl.h
# modified: net/ipv4/netfilter/ipt_ecn.c
# modified: net/netfilter/xt_dscp.c
# modified: net/netfilter/xt_hl.c
# modified: net/netfilter/xt_rateest.c
# modified: net/netfilter/xt_tcpmss.c
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# samples/hidraw/
no changes added to commit (use "git add" and/or "git commit -a")
我想知道这些变化来自哪里。 现在是最糟糕的部分。让我们看看如果我试图摆脱这些文件并再次检查它们会发生什么。
axel@macbook ~/Depots/linux $ rm -Rf include net
axel@macbook ~/Depots/linux $ git checkout -- .
axel@macbook ~/Depots/linux $ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: include/linux/netfilter/xt_CONNMARK.h
# modified: include/linux/netfilter/xt_DSCP.h
# modified: include/linux/netfilter/xt_MARK.h
# modified: include/linux/netfilter/xt_RATEEST.h
# modified: include/linux/netfilter/xt_TCPMSS.h
# modified: include/linux/netfilter_ipv4/ipt_ECN.h
# modified: include/linux/netfilter_ipv4/ipt_TTL.h
# modified: include/linux/netfilter_ipv6/ip6t_HL.h
# modified: net/ipv4/netfilter/ipt_ECN.c
# modified: net/netfilter/xt_DSCP.c
# modified: net/netfilter/xt_HL.c
# modified: net/netfilter/xt_RATEEST.c
# modified: net/netfilter/xt_TCPMSS.c
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# samples/hidraw/
no changes added to commit (use "git add" and/or "git commit -a")
嗯,同样的事情。
git checkout
操作似乎产生了神秘变化的文件。
我试图进一步调查, 我认为我消除了这些变化是由行结束问题引起的可能性 。请参阅下方git diff
的开头
diff --git a/include/linux/netfilter/xt_CONNMARK.h b/include/linux/netfilter/xt_CONNMARK.h
index 2f2e48e..efc17a8 100644
--- a/include/linux/netfilter/xt_CONNMARK.h
+++ b/include/linux/netfilter/xt_CONNMARK.h
@@ -1,6 +1,31 @@
-#ifndef _XT_CONNMARK_H_target
-#define _XT_CONNMARK_H_target
+#ifndef _XT_CONNMARK_H
+#define _XT_CONNMARK_H
-#include <linux/netfilter/xt_connmark.h>
+#include <linux/types.h>
-#endif /*_XT_CONNMARK_H_target*/
+/* Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
+ * by Henrik Nordstrom <hno@marasystems.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
如果我理解这一点,那么就会显示仅通过更改某些行结尾而无法做出的更改,对吧?
我做的最后一件事是:尝试找出变化的发起者,但显然这不起作用。请参阅以下git blame
输出。
axel@macbook ~/Depots/linux $ git blame include/linux/netfilter/xt_CONNMARK.h
00000000 (Not Committed Yet 2011-10-25 20:00:56 +0200 1) #ifndef _XT_CONNMARK_H
00000000 (Not Committed Yet 2011-10-25 20:00:56 +0200 2) #define _XT_CONNMARK_H
2e4e6a17 (Harald Welte 2006-01-12 13:30:04 -0800 3)
00000000 (Not Committed Yet 2011-10-25 20:00:56 +0200 4) #include <linux/types.h>
0dc8c760 (Jan Engelhardt 2008-01-14 23:38:34 -0800 5)
00000000 (Not Committed Yet 2011-10-25 20:00:56 +0200 6) /* Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
00000000 (Not Committed Yet 2011-10-25 20:00:56 +0200 7) * by Henrik Nordstrom <hno@marasystems.com>
00000000 (Not Committed Yet 2011-10-25 20:00:56 +0200 8) *
00000000 (Not Committed Yet 2011-10-25 20:00:56 +0200 9) * This program is free software; you can redistribute it and/or modify
00000000 (Not Committed Yet 2011-10-25 20:00:56 +0200 10) * it under the terms of the GNU General Public License as published by
00000000 (Not Committed Yet 2011-10-25 20:00:56 +0200 11) * the Free Software Foundation; either version 2 of the License, or
00000000 (Not Committed Yet 2011-10-25 20:00:56 +0200 12) * (at your option) any later version.
00000000 (Not Committed Yet 2011-10-25 20:00:56 +0200 13) */
我错过了什么?我什么时候可能出错,以及如何解决这个问题? 感谢您的提示和评论!
答案 0 :(得分:29)
Linux源代码树的文件名仅在大小写不同的情况下,在具有不区分大小写的文件系统的系统上导致感兴趣的失败。
您需要一个区分大小写的文件系统才能使用Linux源代码。
(include/linux/netfilter/xt_connmark.h
和include/linux/netfilter/xt_CONNMARK.h
是Git存储库中的两个不同文件,但如果您的文件系统不区分大小写,则一次只能在结帐中存在一个文件。)
答案 1 :(得分:0)
尝试更新子模块。当存储库中包含的子模块已更新时,我遇到了一些奇怪的,有些类似的问题。做git submodule update
可能会有所作为。
答案 2 :(得分:0)
正如@ephemient所说,这是因为不区分大小写的文件系统。而且我猜你使用的是Mac的HFS?
对于Mac上的简单解决方案,您可以创建磁盘映像,使用“区分大小写的Journaled HFS +”格式化磁盘映像:
hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 40g ~/git.dmg
然后按open ~/git.dmg
安装磁盘映像。
然后在可装入的卷中执行所有git clone
,git checkout
操作。
或者您需要一些第三方工具将HFS +从不区分大小写转换为区分大小写。据我所知,有些Mac应用程序是在不区分大小写的文件系统上制作的,因此如果进行此转换,其中一些可能无法正常工作。