3

git patch 笔记

 2 years ago
source link: https://guonaihong.github.io/post/git-patch-notes/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

前段时间,由于sh的git仓库缺少运维,所以迁移到bj。迁移之后发现其中某个git的commit信息丢失。 下面记录下一种,git commit 合并的方式。同时满足以下所有情况特别适用。

  • old和new是两个仓库
  • new的代码和old是同一个项目的代码
  • old包含所有历史commit记录的仓库
  • new包含old所有代码,只是丢弃了old的所有commit记录
  • new在此基础又多了很多commit记录

操作new仓库生成patch

首先把某个commit(不包含这个commit本身)的后面提交都生成path

# be19a5a42c1ffeba1df02090c574fe12e59d1990 commit之前的所有commit都会生成一个个patch文件
# 不包含be19a5a42c1ffeba1df02090c574fe12e59d1990 本身
git format-patch -s be19a5a42c1ffeba1df02090c574fe12e59d1990

拷贝*.pcath到新的仓库

cp new/*.path ~/old #把new的path拷贝到old
git am *.patch      #把new生成处理的path引用到old, 这么操作是old仓库有历时所有记录

可能遇到的问题

1.少文件

应用:修改
应用:升级gomod版本
应用:修改参数报错问题,修改日志入库错误问题
.git/rebase-apply/patch:49: new blank line at EOF.
+
error: start.sh:不存在于索引中
打补丁失败于 0003 修改参数报错问题,修改日志入库错误问题
用 'git am --show-current-patch' 命令查看失败的补丁
当您解决这一问题,执行 "git am --continue"。
如果您想要跳过这一补丁,则执行 "git am --skip"。
若要复原至原始分支并停止补丁操作,执行 "git am --abort"。
  • 分析:少文件一般是patch里面没有包含这个文件的修改
  • 解决方法:把new仓库的这个文件copy过来

2.文件冲突

应用:up Makefile
error: 打补丁失败:.gitignore:2
error: .gitignore:补丁未应用
.git/rebase-apply/patch:70: new blank line at EOF.
+
打补丁失败于 0007 up Makefile
用 'git am --show-current-patch' 命令查看失败的补丁
当您解决这一问题,执行 "git am --continue"。
如果您想要跳过这一补丁,则执行 "git am --skip"。
若要复原至原始分支并停止补丁操作,执行 "git am --abort"。
  • 分析: 文件冲突
  • 解决方法: 使用new仓库的文件为基础

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK