【问题标题】:How to remove white space file before commit and upload on git如何在提交和上传到 git 之前删除空白文件
【发布时间】:2015-02-20 06:46:12
【问题描述】:

如果有空白更改预期一般更改,我们如何取消提交文件

我点击链接Commit without whitespace changes on github

【问题讨论】:

    标签: github


    【解决方案1】:

    如果您已经在本地 repo 中提交,您可以删除上次提交文件中的空白:

    git rebase --whitespace=fix HEAD~
    

    (如“git remove trailing whitespace in new files before commit”中所述)

    请注意,如果您已经在 GitHub 上推送了错误提交,则需要 git push --force 来发布已修复的提交:如果其他人已经从同一个 GitHub 获取,这可能会出现问题回购。


    如果您不想将该修复应用于提交的所有文件,而仅应用于特定文件,之前提交,您可以创建一个基于补丁在其 git diff 上,并使用 git apply --whitespace=fix 选项应用该补丁。

    参见Bruno Bronosky 的“git-fix-whitespace”。


    2020 年 10 月更新(五年后):您现在在 GitHub 端有了替代方案,使用 GitHub Action
    见“How to avoid whitespace being committed with GitHub?”。

    【讨论】:

    • 就像我们使用了 git diff 来显示差异,如果有空白,我们会为空白做什么,然后文件不会列出它列出的其他内容
    • @smartdeveloper 如果 git diff 显示有差异,那么您可以应用我提到的 git-fix-whitespace 来修复它。然后添加并提交。
    • git -fix -whitespace 未知选项:-fix 用法:git [--version] [--help] [-C ] [-c name=value] [--exec-路径[=]] [--html-path] [--man-path] [--info-path] [-p|--paginate|--no-pager] [--no-replace-对象] [--bare] [--git-dir=] [--work-tree=] [--namespace=] []
    • @smartdeveloper 使用该脚本 (raw.githubusercontent.com/RichardBronosky/git-fix-whitespace/…) 的方式是将其复制到 PATH 引用的文件夹中,然后将文件添加到索引中(带有空格问题),然后调用带有git fix-whitespace --cached 的脚本(注意gitfix-whitespace 之间的空格)
    • abc@abc:/var/www/zends$ git fix-whitespace --cached git: 'fix-whitespace' 不是 git 命令。请参阅“git --help”。 pankaj@kindlebit-desktop:/var/www/zends$
    猜你喜欢
    • 2013-10-09
    • 2015-12-01
    • 2011-08-19
    • 2021-11-22
    • 1970-01-01
    • 2017-06-15
    • 1970-01-01
    • 2011-01-29
    • 2014-01-02
    相关资源
    最近更新 更多