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>
相关推荐
petunsecn1 小时前
多 GitHub 账号与多平台 Git 使用(附加场景:就想用指定账号clone)
git·github
yuanmenghao2 小时前
Git submodule 与 git-repo(Google 的 repo 工具) 在多仓库管理上的差异
git
木易双人青2 小时前
git常用命令
git
热忱11283 小时前
Git 全套常用命令手册(含日常开发示例)
大数据·git·elasticsearch·搜索引擎
Aliex_git3 小时前
Git SSH 配置
笔记·git·学习·ssh
小舞O_o3 小时前
gitlab文件上传
linux·服务器·git·python·目标检测·机器学习·gitlab
C++ 老炮儿的技术栈11 小时前
在C++ 程序中调用被 C编译器编译后的函数,为什么要加 extern “C”声明?
c语言·c++·windows·git·vscode·visual studio
Robin罗兵14 小时前
git使用教程2
git
bob_young17 小时前
Git LFS + Gerrit 配置+lfs-test-server(git lfs push总是提示输入https密码解决)
git·lfs
半夏微凉半夏殇19 小时前
git add . 是否会包含.o、.so、.ko文件?深度解析与避坑指南
git