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>
相关推荐
Bigger6 小时前
为什么你的 Git 提交需要签名?—— Git Commit Signing 完全指南
git·开源·github
DianSan_ERP20 小时前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
红豆子不相思1 天前
Tomcat 环境搭建与集群实战
服务器·git·tomcat
杰哥技术分享1 天前
Git 仓库迁移技术文档:从 CODING.net 迁移至腾讯云 CNB
git
梅孔立1 天前
Ansible 100 台服务器一键管控实战 进阶版
服务器·git·ansible
qq_426003962 天前
git切换当前分支到远程分支
git
ON10N2 天前
100% 纯 Vibe Coding,我是怎么用 AI 撸出一个 VS Code 插件的
git·ai编程·visual studio code
Lunar*2 天前
告别臃肿!使用 git-filter-repo 优雅清理 Git 历史记录
git
tq10862 天前
agent 记忆 = markdown + json + git
人工智能·git
何以不说话2 天前
DevOps、Git 和 GitLab
git·gitlab·devops