【发布时间】:2011-12-15 04:22:06
【问题描述】:
我在 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) */
问题
我错过了什么?我什么时候会出错,以及如何解决这个问题? 感谢您的提示和评论!
【问题讨论】:
-
你试过
git reset --hard吗?它应该将分支重置为上次提交的状态。也就是说我不知道为什么git checkout不起作用... -
是的,我有。如果你愿意,我可以发布输出,但基本上它只是提醒我
HEAD在哪里。它返回 0。不过,在那之后,git status没有改变。 -
使用 Git 2.20(2018 年第四季度),您将在 git 克隆期间收到警告,包括任何区分大小写的遮蔽:请参阅“Cloning a git repo, and it already has a dirty working directory”。
标签: linux macos git git-checkout