使用场景
介绍的时候就有人问,这个是不跟git cherry-pick
一样,为啥还要搞出个文件,这就是没有理解场景。
有一个从github上clone下来的项目,本地做了一些修改,在公司的git库里管理,这些修改同时又push到给客户提供的仓库里了。
但是是程序就可能 有bug,我还要从github上更新一些开源者fix的bug,或者新功能到我的项目里。
同时,一些我用不到的功能我就不用管了。
当然,如果是源代码库的代码全部应用的话,也可以在git上加多个remote来解决,但是冲突是无法避免的。
git-cherry适合同一个库多个分支之间合并代码。
git batch 适合选择性的在库与库之间应用补丁。
好处
- 可以分文件或者commit查看diff,事先review,做到心中有数。
- 多个库之间可以选择性应用commit
- 应用patch时可以分详细差异应用,灵活
- 多人协作无法提交或者帮忙,可以用patch文件提供给队友(巴巴拉拉指导半天,不如直接给个文件)
gitlab提供的人性化操作:
image.png
实践
以应用我操作的库上的一次commit为例。
github commit git diff1. 打补丁
此处git format-patch
的灵活使用需要自学一下。
# mahaiqiang @ MacBook-Pro in ~/git/opensource/electron/vue-pc-chat on git:master o [16:55:47]
$ git format-patch 35c021b82a4ea1e6f827e82788a89a5d7e903b1d -1
0001-.patch
# mahaiqiang @ MacBook-Pro in ~/git/opensource/electron/vue-pc-chat on git:master x [16:55:50]
$ cat 0001-.patch
From 35c021b82a4ea1e6f827e82788a89a5d7e903b1d Mon Sep 17 00:00:00 2001
From: x86 <1960867973@qq.com>
Date: Wed, 7 Jul 2021 22:28:00 +0800
Subject: [PATCH] =?UTF-8?q?=E5=B1=95=E7=A4=BA=E7=94=A8=E6=88=B7=E8=AF=A6?=
=?UTF-8?q?=E6=83=85=E9=A1=B5=E6=97=B6=EF=BC=8C=E5=88=B7=E6=96=B0=E4=B8=80?=
=?UTF-8?q?=E4=B8=8B=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/ui/main/HomePage.vue | 5 +++++
src/ui/main/contact/UserDetailView.vue | 5 +++++
.../message/NormalInMessageContentContainerView.vue | 5 +++++
.../message/NormalOutMessageContentContainerView.vue | 6 +++++-
4 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/src/ui/main/HomePage.vue b/src/ui/main/HomePage.vue
index 0b73c80..bc5ed60 100644
--- a/src/ui/main/HomePage.vue
+++ b/src/ui/main/HomePage.vue
@@ -27,6 +27,7 @@
name="infoTrigger"
class="avatar"
draggable="false"
+ @click="onClickPortrait()"
:src="sharedContactState.selfUserInfo.portrait"
alt=""
/></a>
@@ -135,6 +136,9 @@ export default {
},
methods: {
+ onClickPortrait() {
+ wfc.getUserInfo(this.sharedContactState.selfUserInfo.uid, true);
+ },
go2Conversation() {
if (this.$router.currentRoute.path === '/home') {
return
@@ -469,6 +473,7 @@ i.active {
background: #f2f2f280;
box-shadow: 0 0 1px #000;
}
+
.voip-iframe-container {
background: #292929;
position: absolute;
diff --git a/src/ui/main/contact/UserDetailView.vue b/src/ui/main/contact/UserDetailView.vue
index 6474fb8..f6b55e8 100644
--- a/src/ui/main/contact/UserDetailView.vue
+++ b/src/ui/main/contact/UserDetailView.vue
@@ -41,6 +41,7 @@
import store from "@/store";
import ConversationType from "@/wfc/model/conversationType";
import Conversation from "@/wfc/model/conversation";
+import wfc from "../../../wfc/client/wfc";
export default {
name: "UserDetailView",
@@ -71,6 +72,10 @@ export default {
} else {
name = friend.name;
}
+ // side
+ (async () => {
+ wfc.getUserInfo(friend.uid, true)
+ })();
return name;
}
}
diff --git a/src/ui/main/conversation/message/NormalInMessageContentContainerView.vue b/src/ui/main/conversation/message/NormalInMessageContentContainerView.vue
index c899e7c..0252943 100644
--- a/src/ui/main/conversation/message/NormalInMessageContentContainerView.vue
+++ b/src/ui/main/conversation/message/NormalInMessageContentContainerView.vue
@@ -22,6 +22,7 @@
v-model="sharedPickState.messages"/>
<img ref="userCardTippy"
:name="'infoTrigger' + this.message.messageId"
+ @click="onClickUserPortrait(message.from)"
class="avatar"
draggable="false"
:src="message._from.portrait">
@@ -56,6 +57,7 @@ import MessageContentContainerView from "@/ui/main/conversation/message/MessageC
import QuoteMessageView from "@/ui/main/conversation/message/QuoteMessageView";
import LoadingView from "@/ui/common/LoadingView";
import store from "@/store";
+import wfc from "../../../../wfc/client/wfc";
export default {
name: "NormalInMessageContentView",
@@ -69,6 +71,9 @@ export default {
}
},
methods: {
+ onClickUserPortrait(userId) {
+ wfc.getUserInfo(userId, true);
+ },
closeUserCard() {
console.log('closeUserCard')
this.$refs["userCardTippy"]._tippy.hide();
diff --git a/src/ui/main/conversation/message/NormalOutMessageContentContainerView.vue b/src/ui/main/conversation/message/NormalOutMessageContentContainerView.vue
index 0c7ecfa..726ddef 100644
--- a/src/ui/main/conversation/message/NormalOutMessageContentContainerView.vue
+++ b/src/ui/main/conversation/message/NormalOutMessageContentContainerView.vue
@@ -41,6 +41,7 @@
<img ref="userCardTippy"
:name="'infoTrigger' + this.message.messageId"
class="avatar"
+ @click="onClickUserPortrait(message.from)"
draggable="false"
:src="message._from.portrait">
</div>
@@ -88,6 +89,9 @@ export default {
},
methods: {
+ onClickUserPortrait(userId) {
+ wfc.getUserInfo(userId, true);
+ },
closeUserCard() {
console.log('closeUserCard', this.$refs["userCardTippy"]);
this.$refs["userCardTippy"]._tippy.hide();
@@ -207,7 +211,7 @@ export default {
if (this.message.messageContent.quoteInfo) {
let messageUid = this.message.messageContent.quoteInfo.messageUid;
let msg = store.getMessageByUid(messageUid);
- if(!msg){
+ if (!msg) {
console.log('quotedMessage, is null', this.message.messageContent.quoteInfo)
}
return msg;
--
2.29.2
2. 应用补丁
# mahaiqiang @ MacBook-Pro in ~/git/mygitrepo/vue-pc-chat on git:master o [16:57:39]
$ git apply --check /Users/mahaiqiang/git/opensource/electron/vue-pc-chat/0001-.patch
error: 打补丁失败:src/ui/main/conversation/message/NormalOutMessageContentContainerView.vue:207
error: src/ui/main/conversation/message/NormalOutMessageContentContainerView.vue:补丁未应用
# mahaiqiang @ MacBook-Pro in ~/git/mygitrepo/vue-pc-chat on git:master o [16:58:33] C:1
$ git apply --reject /Users/mahaiqiang/git/opensource/electron/vue-pc-chat/0001-.patch
正在检查补丁 src/ui/main/HomePage.vue...
块 #2 成功应用于 140(偏移 4 行)
块 #3 成功应用于 477(偏移 4 行)
正在检查补丁 src/ui/main/contact/UserDetailView.vue...
块 #1 成功应用于 39(偏移 -2 行)
块 #2 成功应用于 70(偏移 -2 行)
正在检查补丁 src/ui/main/conversation/message/NormalInMessageContentContainerView.vue...
正在检查补丁 src/ui/main/conversation/message/NormalOutMessageContentContainerView.vue...
error: 当查询:
if (this.message.messageContent.quoteInfo) {
let messageUid = this.message.messageContent.quoteInfo.messageUid;
let msg = store.getMessageByUid(messageUid);
if(!msg){
console.log('quotedMessage, is null', this.message.messageContent.quoteInfo)
}
return msg;
error: 打补丁失败:src/ui/main/conversation/message/NormalOutMessageContentContainerView.vue:207
成功应用补丁 src/ui/main/HomePage.vue。
成功应用补丁 src/ui/main/contact/UserDetailView.vue。
成功应用补丁 src/ui/main/conversation/message/NormalInMessageContentContainerView.vue。
应用 src/ui/main/conversation/message/NormalOutMessageContentContainerView.vue 个补丁,其中 1 个被拒绝...
第 #1 个片段成功应用。
第 #2 个片段成功应用。
拒绝第 #3 个片段。
# mahaiqiang @ MacBook-Pro in ~/git/mygitrepo/vue-pc-chat on git:master x [16:59:53] C:1
$
3. 解决冲突
1、用任何工具查看冲突
冲突2、解决完冲突后删除后缀为 .rej 的文件,并执行git add.添加改动到暂存区.
3、接着执行git am --resolved或者git am --continue
说明:在打入patch冲突时,可以执行git am --skip跳过此次冲突,也可以执行git am --abort回退打入patch的动作,还原到操作前的状态。
$ git add .
# mahaiqiang @ MacBook-Pro in ~/git/mygitrepo/vue-pc-chat on git:master x [17:14:00]
$ git am --continue
应用:展示用户详情页时,刷新一下用户信息
# mahaiqiang @ MacBook-Pro in ~/git/mygitrepo/vue-pc-chat on git:master o [17:14:02]
$ git lg
# mahaiqiang @ MacBook-Pro in ~/git/mygitrepo/vue-pc-chat on git:master o [17:15:13]
$ git push
枚举对象中: 22, 完成.
对象计数中: 100% (22/22), 完成.
使用 8 个线程进行压缩
压缩对象中: 100% (12/12), 完成.
写入对象中: 100% (12/12), 3.78 KiB | 3.78 MiB/s, 完成.
总共 12(差异 10),复用 0(差异 0),包复用 0
remote: Powered by GITEE.COM [GNK-6.0]
To gitee.com:marvinma/vue-pc-chat.git
87c3de9..2730f33 master -> master
# mahaiqiang @ MacBook-Pro in ~/git/mygitrepo/vue-pc-chat on git:master o [17:15:20]
$
push log
push
网友评论