当前位置:网站首页>【P4】解决本地文件修改与库文件间的冲突问题
【P4】解决本地文件修改与库文件间的冲突问题
2022-07-28 03:25:00 【MangoPapa】
声明:
- 🥭 作者主页:【MangoPapa的CSDN主页】。
- ️ 本文首发于CSDN,转载或引用请注明出处 https://mangopapa.blog.csdn.net/article/details/125939590。
- ️ 本文为非盈利性质,目的为 个人学习记录 及 知识分享。因个人能力受限,存在协议解读不正确的可能。若您参考本文进行产品设计或进行其他事项并造成了不良后果,本人不承担相关法律责任。
- ️ 若本文所采用图片或相关引用侵犯了您的合法权益,请联系我进行删除。
- 欢迎大家指出文章错误,欢迎同行与我交流 ~
- 邮箱:[email protected]
引言
本专栏记录一些个人常用的 命令组合 或 脚本。脚本包括但不限于 shell、python、perl。
本篇为《【P4】解决本地文件修改与库文件间的冲突问题》。
更多实用脚本 点击查看总目录。
需求提出
公司采用 perforce 进行 code 版本管理,同一团队在同一 branch 下工作。多人把 code check out 到本地,edit 后再 submit 上传库中。若 A 和 B 对同一文件 F 进行了 edit,A 先于 B 将 文件 F 上传,待 B 上传时,就会出现本地修改与库文件版本冲突的问题。
常用的方法是 p4 resolve 把个人改动与他人改动 merge 到一起。p4 resolve 的 merge 参数如表 1 所示。
| 参数 | 释义 |
|---|---|
| -am | 谁跟 base 不一致接受谁的,若两人的均与 base 不一致,两人改动不冲突则自动 merge,两人改动冲突则忽略。 |
| -as | 谁跟 base 不一致接受谁的,若两人的均与 base 不一致,不管冲不冲突均忽略。 |
| -ay | 接受我方的改动。 |
| -at | 接受他方的改动。 |
大部分情况下,两人的改动是会冲突的,需要手动把我方改动与库里的他人改动 merge 到一起。此时需要一系列操作来完成手动 merge。考虑到每次手动 merge 都是那么几个命令,干脆封装下得了。
脚本特性
- 生成原文件的本地备份,原文件名添加时间戳作为备份文件名。
- 原文件 revert 并 sync 到最新版本,与库版本对齐。
- resolve 完毕后,CL 仍与 resolve 前的 CL 相同。
- 需要 p4 diff 手动 merge。
脚本
脚本名为 m_resolve.sh,为方便使用请在 ~/.bashrc 里 alias m_resolve 'sh ~/script/m_resolve.sh'。
#! /usr/bin/sh
# File Name: m_resolve.sh
# Usage : sh m_resolve.sh conflicted_file
timestamp=$(data +%Y%m%d%H%M%S)
ori_file=$1
bak_file=.$ori_file.$timestamp
# get CL
CL=`p4 opened $ori_file`
CL=`echo ${
CL#*\edit change}` # keep right
CL=`echo ${
CL%% *}` # keep left
#
cp $ori_file $bak_file
p4 revert $ori_file
p4 sync $ori_file
p4 edit $ori_file
cp $bak_file $ori_file
p4 reopen -c $CL $ori_file
p4 diff $ori_file
边栏推荐
猜你喜欢

12月份PMP考试首次采用新考纲,该怎么学?

C language to achieve a dynamic version of the address book

单调栈——42. 接雨水——面大厂必须会的困难题

Defect detection of BP SVM system design of leaf defect detection

xctf攻防世界 Web高手进阶区 PHP2

Airiot Q & A issue 6 | how to use the secondary development engine?

20220727使用汇承科技的蓝牙模块HC-05配对手机进行蓝牙串口的演示

Redis基本操作

Shell:资源监控脚本和高负载报警

每日练习------实现双色球的彩票功能。规则:从36个红球中随机选择不重复的6个数,从15个篮球中随机选择1个组成一注彩票。可以选择买多注。
随机推荐
Shell: one click deployment PXE
[5g NR] RRC reject analysis
MySQL事务的ACID特性及并发问题实例分析
Leetcode 29th day
203. Remove linked list elements
695. Maximum area of the island
动态内存管理中的malloc、free、calloc、realloc动态内存开辟函数
Shell writing specifications and variables
golang gorm查询任意字段的组装方法
Summary of redis classic interview questions
Summary of concurrent programming interview questions
鼠标操作和响应
Shell编写规范和变量
Light year admin background management system template
2022-07-27: Xiao Hong got an array arr with a length of N. she is going to modify it only once. She can modify any number arr[i] in the array to a positive number not greater than P (the modified numb
Super nice PHP program source code of nteam official website
Redis implements distributed locks
[SAML SSO solution] Shanghai daoning brings you SAML for asp NET/SAML for ASP. Net core download, trial, tutorial
贪心——122. 买卖股票的最佳时机 II
D2dengine edible tutorial (4) -- draw text