Подтвердить что ты не робот

Странное поведение Git: таинственные изменения не могут быть отменены

Я вижу поведение в Git, которое кажется мне очень загадочным. Я сохраняю клон репозитория Linux из Github, чтобы играть с Git локально. Чтобы быть ясным, я не очень много делаю в этом репозитории: я извлекаю изменения, обновляю master, проверяю определенную версию, а иногда я пробую графический интерфейс Git, чтобы увидеть, как выглядит визуализация в большом проекте. Версия TL;DR: Я никогда не делал никаких изменений в файлах в ней.

Странное поведение

Ранее сегодня я проверил master и вытащил изменения из Github. Казалось, все в порядке. Но я подозреваю, что на самом деле это не так. Вот что выглядит git status.

[email protected] ~/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")

Откуда эти изменения исходят, интересно. Сейчас наступает худшая часть. Посмотрим, что произойдет, если я попытаюсь избавиться от этих файлов и проверить их снова.

[email protected] ~/Depots/linux $ rm -Rf include net
[email protected] ~/Depots/linux $ git checkout -- .
[email protected] ~/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 <[email protected]>
+ *
+ * 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.

[email protected] ~/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 <[email protected]>
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)  */

Вопросы

Что мне не хватает? Когда я мог поступить неправильно и как это исправить? Спасибо за ваши советы и замечания!

4b9b3361

Ответ 1

В исходном дереве Linux есть имена файлов, которые различаются только в случае, что вызывает интересные сбои в системах с файловыми системами, не зависящими от регистра.

Для работы с источником Linux нужна файловая система с учетом регистра.

(include/linux/netfilter/xt_connmark.h и include/linux/netfilter/xt_connmark.h - это два разных файла в репозитории Git, но только один может существовать в вашем контроле за раз, если ваша файловая система нечувствительна к регистру.)

Ответ 2

Попробуйте обновить подмодули. У меня возникли некоторые странные, несколько схожие проблемы, когда обновлялся подмодуль, включенный в репозиторий. Выполнение git submodule update может сделать трюк.

Ответ 3

Как сказал @emhemient, это происходит из-за нечувствительной к регистру файловой системы. И я думаю, вы используете Mac HFS?

Для простого решения на Mac вы можете создать образ диска, форматировать образ диска с помощью "Case-sensitive Journaled HFS +":

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

Затем смонтируйте образ диска с помощью open ~/git.dmg.

И затем выполняйте все операции git clone, git checkout в монтируемых томах.


Или вам нужен сторонний инструмент для преобразования HFS + с регистрозависимой чувствительностью к регистру. Как я знаю, некоторые Mac-приложения созданы на нечувствительных к регистру файловых системах, поэтому некоторые из них могут не работать, если вы делаете это преобразование.