git 技巧
来源:互联网 发布:nginx防止cc攻击配置 编辑:程序博客网 时间:2024/06/02 01:59
1. git add 忽略空白修改
有时候只修改了几行代码,但是git diff时一大片代码都红了,git add 又没–ignore-space-change选项。在stackoverflow找了一个不错的方法。
为了方便可以绑定别名
alias.addnw=!sh -c 'git diff -U0 -w --no-color "$@" | git apply --cached --ignore-whitespace --unidiff-zero -'
或者直接运行
git diff -U0 -w --no-color | git apply --cached --ignore-whitespace --unidiff-zero -
使用方法
git addnw your/file
参数解释
Added options -U0, and –unidiff-zero respectively to workaround context matching issues, according to this comment.
Basically it applies the patch which would be applied with add without whitespace changes. You will notice that after a git addnw your/file there will still be unstaged changes, it’s the whitespaces left.
The –no-color isn’t required but as I have colors set to always, I have to use it. Anyway, better safe than sorry.
2. git format-patch 不自动省略中括号
如果commit注释首行是以中括号[xxx]开头的,直接使用git am打补丁会去掉注释中的[xxx],这时候使用-k,参数就可以解决这个问题。
生成补丁
git format-patch -k -1 comnit_id
打补丁
git am -k patch_file
3. 修改未push到服务器的提交的注释
只修改最后一次提交的
git commit --amend
修改历史提交的话,使用rebase命令,例如前两个提交
git rebase -i HEAD~2
接着在弹出的编辑框中,将pick改成e,然后
git commit --amend
修改完成,执行命令,继续修改
git rebase --continue
直到全部修改完成
- GIT技巧
- git 技巧
- Git 技巧
- Git技巧
- Git - 技巧
- Git - 技巧
- git 技巧
- Git技巧
- git 技巧
- git 技巧
- Git技巧
- git技巧
- Git 技巧
- git技巧
- git 技巧
- Git使用技巧篇
- git 小技巧
- Git 技巧记录
- java中异常处理finally和return语句的执行顺序
- 遍历map集合的四种方式
- F1V3.0-6 平台V3.0 UI体系架构
- [线段树] Codeforces Round #419 (Div. 1) D. Karen and Cards
- OSI七层模型详解
- git 技巧
- SQL复杂查询(二)
- 关于Android.9图片的处理和注意事项
- 面试题40. 数组中只出现一次的数字
- Java数据类型
- 微信网页授权获取用户信息 返回{"errcode":40066,"errmsg":"invalid url hint: [FZbxRA0556sz12!]"}错误
- 半路出家, 我的iOS自学之路-4-Block的声明,定义,闭包性,强引用循环
- vagrant
- Json与XML辅助类(读写存操作)