1

我花了很长时间阅读并试图弄清楚 git commit --amend,但我仍然不明白 # 在 editmsg 中是如何使用的。

我担心在不知道自己在做什么的情况下对其进行编辑,因为我已阅读 git commit --amend 仅执行最近的提交,并且一旦我保存并退出,它将被视为新提交。

我不小心提交并推送(但推送失败)一些大文件。但我也编写了应该从与大文件相同的提交中推送的脚本。

我正在尝试删除新提交中包含大文件的行,但我不明白如何执行此操作。

这是我下面的提交文件,但我不明白是否应该删除带有 # 的行(我试过了,但没有用,git log 是一样的):

the commit message of the one I want to change is here but I don't want to just change the message, I want to delete the large files in the commit so that the push works.

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Thu Feb 8 18:30:32 2018 -0900
#
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#   (use "git push" to publish your local commits)
#
# Changes to be committed:
#   new file:   script.py
#   new file:   super_large_file.npy <--- I deleted this line but it appeared again, it is becuase deleting a line with # is ignored?  Do I just rewrite the stuff after the # lines? 

我的问题是,为什么删除大文件的行(包括 # )不起作用并且提交仍然想要推送大文件?

我应该只重写没有 # 的提交文件吗?但我也读到 git 拿走了 # ,所以我很困惑

4

2 回答 2

1

首先,这些是注释:删除以开头的行#对您的 git 存储库内容没有影响。
它们包括提示和提交中包含的文件列表。

我建议,为了从您的回购历史记录中真正删除该文件,使用git filter-repo替换BFG 和git filter-branch.

注意:如果您在运行上述命令时收到以下错误消息:

Error: need a version of `git` whose `diff-tree` command has the `--combined-all-paths` option`

这意味着你必须更新git


第一:做一个本地仓库的副本(一个新的克隆)

请参阅“基于路径的过滤”:

git filter-repo --path file-to-remove --invert-paths

最后,您可以(如果您是唯一在该存储库上工作的人)执行git push --force


其次,随着 Git 2.25.1(2020 年 2 月)的变化,提交消息中显示的提示发生了变化:当没有任何要提交的内容但不遵守配置变量git commit时,“ ”给出类似于“”的输出,这已得到纠正。 见讨论git statusadvise.statusHints

请参阅Heba Waly ( ) 的提交 5c4f55f(2019 年 12 月 17 日(由Junio C Hamano 合并 -- --提交 9403e5d中,2020 年 1 月 22 日)HebaWaly
gitster

commitadvice.statusHints:拒绝空提交时的荣誉

签字人:Heba Waly

ea9882bfc4(提交:写入COMMIT_EDITMSG,2013-09-12 时禁用状态提示)中,目的是在写入时禁用状态提示,COMMIT_EDITMSG,因为在“git status”中给出提示,如在提交消息模板中的输出为时已晚,无法使用(他们说诸如“'git add' to stage”之类的东西,但这只有在中止当前的“git commit”会话后才有可能)。

但是在一种情况下,提示可能很有用:当当前的提交尝试被拒绝时,因为 index 中没有记录任何更改

给出消息并且“ git commit”错误输出,因此用户可以立即遵循提示。

教导代码路径遵守配置变量。

提示(现在在提交消息编辑器中可见)将是:

no changes added to commit (use "git add" and/or "git commit -a")
于 2020-01-24T22:18:37.987 回答
0

我尝试了一种不同于修改 commit 的方法,并从我的本地和 github 存储库中完全删除了该文件。我不确定如何将它保存在我的本地存储库中,但我不知道这是否有必要,因为我并不真正了解我的本地存储库和本地驱动器之间的区别。

https://help.github.com/articles/removing-files-from-a-repository-s-history/

(我从 Bluemoon93 在 Can't push to GitHub 的回答中找到了这个链接,因为我已经删除了大文件

于 2018-02-09T19:49:26.737 回答