如何使用git撤消所有空白变化 [英] how to undo all whitespace changes with git

查看:145
本文介绍了如何使用git撤消所有空白变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



git status现在显示很多很多修改过的文件。



有些是真正修改过的,有些只是根据行结尾而有所不同。



我希望只有行结尾不同的行为才会消失git reset them),但是
我似乎无法找到linux-piping-foo来实现它。



如何删除文件

解决方案

这将做到这一点:

  git diff -b --numstat \ 
| egrep $'^ 0 \t0\t'\
| cut -d $'\t'-f3- \
| xargs git checkout HEAD -




  1. 运行工作副本的差异索引并给出每个文件的机器可读摘要,忽略空白的变化。
  2. 根据 diff -b
  3. 取名称。

  4. 将它们传递给 git checkout 分行提示。

这条管道会为您离开的每一步做一些明智的事情,所以您可以从第一条并添加更多以查看每一步发生的情况。



可能有用的替代最后一行:

  | git checkout-index --stdin 

这会将文件重置到他们的staged内容而不是他们的最后您可能还想在第一行使用 git diff HEAD 来获取diff而不是针对索引。






注意:if你需要添加一个 tr

  git diff -b --numstat \ 
| egrep $'^ 0 \t0\t'\
| cut -d $'\t'-f3- \
| tr'\ n''\0'\

然后您必须添加一个 / -z 切换到您想要使用的最终命令:

  | xargs  -0  git checkout HEAD  -  
#或
| git checkout-index --stdin -z


I have a git repo, where I replaced a lot of files locally.

git status now shows many many modified files.

Some are "really modified", others only differ by line endings.

I want the ones that differ only by line endings to go away (git reset them), but I cannot seem to find the linux-piping-foo to make it happen.

Bonus points for how to remove files whose only difference is the executable bit.

解决方案

This will do it:

  git diff -b --numstat \
| egrep $'^0\t0\t' \
| cut -d$'\t' -f3- \
| xargs git checkout HEAD --

  1. Run a diff of the working copy against the index and give a machine-readable summary for each file, ignoring changes in whitespace.
  2. Find the files that had no changes according to diff -b.
  3. Take their names.
  4. Pass them to git checkout against the branch tip.

This pipe will do something sensible for each step you leave off, so you can start off with the just the first line and add more to see what happens at each step.

A possibly useful alternative last line:

| git checkout-index --stdin

This would reset the files to their staged contents instead of to their last committed state.

You may also want to use git diff HEAD on the first line instead, to get a diff of the working copy against the last commit instead of against the index.


Note: if you have filenames with spaces in them, you will first need to add a tr:

  git diff -b --numstat \
| egrep $'^0\t0\t' \
| cut -d$'\t' -f3- \
| tr '\n' '\0' \

Then you must add a -0/-z switch to whichever final command you wanted to use:

| xargs -0 git checkout HEAD --
# or
| git checkout-index --stdin -z

这篇关于如何使用git撤消所有空白变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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