1

问题主要在标题中解释。我的一个存储库包含许多从未真正更改过的二进制文件。但是,我更改了用于新文件扩展名/存储格式的格式。现在我的 git 历史记录中有 1000 个左右的文件没有用(因为数据本身没有改变,只是存储格式)。由于它们都是相同的扩展,我认为这应该是清除它们的一种简单方法,但我不知道如何。

4

1 回答 1

0

I'm still not sure I understood your question correctly. You shouldn't remove nothing from the git history. Even if it's technically possible it's usually not a good practice especially if you already pushed your branch to the remote repository and shared it with others as it modifies SHA-1 of commits that other users might already pulled. All you should do right now is just to remove all files with a given extension, .x in this example:

$ git rm "*.x"
rm 'a/a.x'
rm 'b/c/d/e/g/another.x'
rm 'c.x'

It will remove all tracked files that end with *.x and add them to the staging area:

$ git diff --cached
diff --git a/a/a.x b/a/a.x
deleted file mode 100644
index e69de29..0000000
diff --git a/b/c/d/e/g/another.x b/b/c/d/e/g/another.x
deleted file mode 100644
index e69de29..0000000
diff --git a/c.x b/c.x
deleted file mode 100644
index e69de29..0000000

You will just have to commit them.

Notice you have to put *.x in double quotes as your shell will expand * before running git command.

于 2019-09-20T10:53:06.943 回答