【问题标题】:Strange behaviour of Git: mysterious changes cannot be undoneGit的奇怪行为:无法撤消的神秘更改
【发布时间】: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


【解决方案1】:

Linux 源代码树的文件名仅区分大小写,这会导致具有不区分大小写文件系统的系统有趣失败。

您需要一个区分大小写的文件系统才能使用 Linux 源代码。

include/linux/netfilter/xt_connmark.hinclude/linux/netfilter/xt_CONNMARK.h 是 Git 存储库中的两个不同文件,但如果您的文件系统不区分大小写,则一次只能存在一个文件。)

【讨论】:

  • 谢谢,这就是我要找的答案!太糟糕了,没有不显眼的解决方法。 :-(
  • 同样的事情发生在我身上,当然,虽然我在 linux 中,但是我正在使用一个包含符号链接的存储库,并且 git blame 不能完全识别符号链接,所以将每一行显示为未提交。
【解决方案2】:

尝试更新子模块。当更新存储库中包含的子模块时,我遇到了一些奇怪的、有点类似的问题。执行git submodule update 可能会成功。

【讨论】:

    【解决方案3】:

    正如@ehemient 所说,这是因为文件系统不区分大小写。我猜你正在使用 Mac 的 HFS?

    对于 Mac 上的简单解决方案,您可以创建磁盘映像,使用 'Case-sensitive Journaled HFS+' 格式化磁盘映像:

    hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 40g ~/git.dmg

    然后通过open ~/git.dmg挂载磁盘镜像。

    然后在可挂载卷中执行所有git clonegit checkout 操作。


    或者您需要一些第三方工具来将 HFS+ 从不区分大小写转换为区分大小写。据我所知,一些 Mac 应用程序是在不区分大小写的文件系统上制作的,因此如果您进行此转换,其中一些应用程序可能无法工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-05
      • 2021-02-17
      • 1970-01-01
      • 2012-09-30
      • 2016-12-07
      • 2015-01-30
      • 1970-01-01
      • 2017-03-07
      相关资源
      最近更新 更多