git difftool对比差异,避免推送不相关内容

问题

在利用git进行版本管理的时候,经常会由于对其他不相关的代码,做了一些小改动,例如删除了一个空行,多了一个缩进等。

为避免将这些不相关的改动也提交到远程,对PR造成不必要的影响,可以利用git diff命令查看两个版本之间的差异,从而删除那些自己"不经意做的改动"。

做法

  1. 下载文件对比工具Beyond Compare

  2. 使Beyond Compare在MAC OS下永久使用

shell 复制代码
# 切换到Applications路径
cd /Applications/Beyond Compare.app/Contents/MacOS

# 重命名启动文件BCompare为BCompare.real
mv BCompare BCompare.real

# 重新生成一个BCompare文件,使用shell,执行删除注册信息文件再运行启动文件动作
vim BCompare

# 插入以下内容后保存退出
!/bin/bash
rm "/Users/$(whoami)/Library/Application Support/Beyond Compare/registry.dat"
"`dirname "$0"`"/BCompare.real $@

# 给BCompare文件添加执行权限
chmod a+x BCompare
  1. 在git中配置diftools工具
shell 复制代码
git config --global diff.tool bc
  1. 打开Beyond Compared后,在该软件设置中安装命令行工具

  2. 在git中比较不同版本的差异

shell 复制代码
// 比较两个commitid之间的区别
git difftool <commitId1>  <commitId2> 

//比较工作区与指定commitid的区别
git difftool <commitId>

//比较缓存区与指定commitid的区别
git --cached <commitId>
相关推荐
徒步僧39 分钟前
mac中文件夹怎么显示.git隐藏文件
git·macos
int WINGsssss21 小时前
Git使用
git
用户0760530354381 天前
Git Revert:安全移除错误提交的方式
git
Good_Starry1 天前
Git介绍--github/gitee/gitlab使用
git·gitee·gitlab·github
云端奇趣2 天前
探索 3 个有趣的 GitHub 学习资源库
经验分享·git·学习·github
F_D_Z2 天前
【解决办法】git clone报错unable to access ‘xxx‘: SSL certificate problem:
网络·git·网络协议·ssl
等风来不如迎风去2 天前
【git】main|REBASE 2/6
git
艾伦~耶格尔2 天前
IDEA 配置 Git 详解
java·ide·git·后端·intellij-idea
云兮杜康2 天前
IDEA中用过git之后文件名颜色全变红
java·git·intellij-idea
睡不醒的小泽2 天前
git merge 和 git rebase
git