git在提交之前删除新文件中的尾部空白 [英] git remove trailing whitespace in new files before commit
问题描述
我知道删除尾随空白可以用预先提交的钩子完成。我有兴趣做手动。我在这里阅读这个问题:
自动制作git提交之前删除尾部空白
Stack Overflow
最接近我想要的答案是automatic版本ntc2 :
(export VISUAL =:& & git -c apply.whitespace = fix add -ue。)&& git结帐。 &安培;&安培; git reset
该命令运行良好,除了它似乎只适用于更改对于已经在回购站中的文件,不是新文件。我有一堆新的文件,这意味着他们还没有进入回购。我想从这些文件中删除空白,所以我尝试添加-A而不是-u,但这并没有什么不同。
<你可以这样做:
要手动清理最后3个提交中的空白, / code> 当我在一个主题分支上工作时,我追踪上游分支(通常通过像这样创建) 允许我放弃最后一个参数从 请注意,与HEAD〜3示例不同的是,如果更改了上游分支,它实际上会更改您的更改! (但这也是我想要的,在我的工作流程中。) I know removing trailing whitespace can be done with a pre-commit hook. I am interested in doing it manually. I read the question here: To manually clean up whitespace from your last 3 commits, you can do this: When I work on a topic branch, I track the upstream branch (usually by creating it like this) Which allows me to drop the last argument from Note that, unlike the HEAD~3 example, this will actually rebase your changes upon the upstream branch if it's changed! (But that's also what I want, in my workflow.) 这篇关于git在提交之前删除新文件中的尾部空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! git rebase --whitespace = fix HEAD〜3
git checkout -b topic -t
git rebase
。所以一旦我完成了&准备合并,我可以快速清理整个主题分支:
git ws
#别名为rebase - whitespace = fix
Make git automatically remove trailing whitespace before committing - Stack Overflow
The answer closest to what I want is the "automatic version" from ntc2:
(export VISUAL=: && git -c apply.whitespace=fix add -ue .) && git checkout . && git reset
That command works well except it seems to be only for changes on files that are already in the repo, not new files. I have a bunch of files that are new, meaning they aren't yet in the repo. I want to remove whitespace from those files so I tried add -A instead of -u but that didn't make a difference.git rebase --whitespace=fix HEAD~3
git checkout -b topic -t
git rebase
. So once I'm done & ready to merge, I can clean the whole topic branch quickly with:git ws
# aliased to rebase --whitespace=fix