如何避免空格被github提交 [英] How to avoid whitespace being commit with github

查看:261
本文介绍了如何避免空格被github提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了两行更改,但是在git中由于空白而显示了更多行更改.对于我们来说,审查确切的代码更改非常困难.

I made a 2 lines of change but in git It shows more lines of changes because of whitespace. Its very difficult for us to review the exact code changes.

下面是我用来推送代码的命令.

The below are the command that I used to push the code.

首先,我将从Different repo中提取代码库并与我的本地库合并.并将我的更改推到我的叉子上,并提高公关.

First I will pull the code base from Different repo and merge with my local. And push my changes to my fork, and raise PR.

git add .
git commit -am "changes"
git pull upstream master
git push origin master

,但是我在git控制台中也没有找到任何空格去除器选项.只有我可以看到"UNIFIED","SPLIT".

but I didn't find any whitespace remover option in my git console as well. Only I can see "UNIFIED", "SPLIT".

屏幕截图

请找到以下示例屏幕快照以供参考.

Please find the below sample screenshot for reference.

有什么方法可以忽略所有正在提交的空格.

Is there any way that we can ignore all whitespace that being commit.

有什么建议线索吗?

推荐答案

查看问题的另一种方法是对更改的方式保持谨慎.

Another way to look at the problem is to be more cautious with the way you stage your changes.

在上面的示例中,您使用两种非常广泛的方法在提交之前搜索代码库中的更改.

In your above example you're using two very broad sweeping ways to search for changes in your codebase before committing.

git add .
git commit -am "changes"

add.参数已经在暂存所有检测到的更改(不完全是,请参见出色的答案

The . parameter for add is already staging all detected changes (not exactly, see the excellent answers here for more details), but on top of that you're using the -a parameter for commit, which I'd describe as redundant overkill, since you're staging ALL changes AGAIN.

您的上下文可能会使我的以下建议或多或少变得切实可行,但您可以考虑手动"添加更改的文件:

Your context may make my following advice more or less practical, but you might consider adding your changed files "manually" :

# check your changes (at this point, whitespace differences should not show up)
git status

# let's assume the above line showed changes in 3 files
git add <path/to/file1> <path/to/file2> <path/to/file3>

# then commit without staging parameter
git commit -m "changes"

如果您觉得该过程很繁琐,请记住:

And if the process seems tedious to you, keep in mind that :

  • 您可以直接从状态输出的右上方复制和粘贴路径,这使它变得快速
  • 还可以使用add -i调用交互模式,该模式允许您迭代查看更改以决定要实际上演的内容.
  • You can copy and paste paths straight from the right above status output, which makes it quick
  • There is also an interactive mode invoked with add -i, which allows you to iteratively look at changes to decide what's to be actually staged.

这篇关于如何避免空格被github提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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