如何在提交并在git上载之前删除空白文件 [英] How to remove white space file before commit and upload on git

查看:65
本文介绍了如何在提交并在git上载之前删除空白文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果空格有变化,我们将如何取消提交文件

我点击链接提交但在github上没有空白更改

解决方案

如果您已经在本地存储库中提交过,则可以使用以下命令删除上次提交文件中的白点:

git rebase --whitespace=fix HEAD~

(如"在提交前git删除新文件中的尾随空白")

请注意,如果您已经 在GitHub上推送了错误的提交,则需要使用git push --force来发布固定的提交:如果其他人已经从同一GitHub上获取了该信息,则可能会出现问题回购.


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

请参见" git-fix-whitespace "通过布鲁诺·布鲁诺斯基.


更新2020年10月(五年后):现在,您可以在GitHub端使用 GitHub Action .
请参阅"如何避免通过GitHub提交空白?".

How we can un-commit a file if there is white space change expect general change

I follow the link Commit without whitespace changes on github

解决方案

If you already committed in your local repo, you can remove whitepaces in files of your last commit with:

git rebase --whitespace=fix HEAD~

(as mentioned in "git remove trailing whitespace in new files before commit")

Note that if you already pushed the bad commit on GitHub, you would need a git push --force to publish the fixed commit: that can be problematic if others have already fetched from that same GitHub repo.


If you don't want to apply that fix to all files of a commit, but only to a specific file, before commit, you can create a patch based on its git diff, and apply that patch with the git apply --whitespace=fix option.

See "git-fix-whitespace" by Bruno Bronosky.


Update Oct. 2020 (five years later): you now have an alternative on GitHub side, using GitHub Action.
See "How to avoid whitespace being committed with GitHub?".

这篇关于如何在提交并在git上载之前删除空白文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆