TypechoJoeTheme

EYblog - Powered by Eyblog

统计
登录
用户名
密码

郑先森灬

世上没有偶然,有的只是必然,正面面对困难,才能迈向成功。
网站页面

【技术解读】GIT分支合并命令


在开发项目的时候,会因为经常操作不断的提交,产生很多的分支,后期不利于回滚数据,下面的方式就可以将分支多个合并:

1、查看提交历史,–oneline -20最近20次提交,每次提交显示一行摘要

git log --oneline -20

该命令可以展示出最近20条的分支历史,具体根据实际情况修改。

2、合并提交历史

#合并前5个提交
git rebase -i HEAD~5

#合并到某个提交
git rebase -i 0b26a0f775

上面的命令可以2选1,根据实际情况选择

3、编辑合并规则

pick 0b064204 最终修改
s c1ad1218 修改文件2
s e4e4034f 创建文件1
s 6e492400 删除文件3

# Rebase be4a2d33..6e492400 onto 6e492400 (4 commands) 【将be4a2d33..6e492400重新设定为6e492400(4个命令)】

# Commands: 
# p, pick <commit> = use commit【使用commit】
# r, reword <commit> = use commit, but edit the commit message【使用commit,但编辑commit消息】
# e, edit <commit> = use commit, but stop for amending【使用commit,但停止修改】
# s, squash <commit> = use commit, but meld into previous commit【使用commit,但合并到上一个commit中】
# f, fixup <commit> = like "squash", but discard this commit's log message【和squash一样,只是丢弃commit的日志消息】
# x, exec <command> = run command (the rest of the line) using shell【run command(行的其余部分)using shell】
# b, break = stop here (continue rebase later with 'git rebase —continue')【在此处停止(稍后使用“git rebase --continue”继续重新base)】
# d, drop <commit> = remove commit【删除commit】
# l, label <label> = label current HEAD with a name【用名称标记当前头部】
# t, reset <label> = reset HEAD to a label【将头部重置为标签】
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>] create a merge commit using the original merge commit's message (or the oneline, if no original merge commit was ). Use -c <commit> to reword the commit message.【使用原始合并提交的消息创建合并提交(如果没有原始合并提交,则为oneline)。使用-c<commit>重新编写commit消息。】
# These lines can be re-ordered; they are executed from top to bottom.
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
# Note that empty commits are commented out
#这些行可以重新排序;它们从上到下执行。如果在此处删除一行,则提交操作将丢失。但是,如果删除所有内容,则将中止重新平衡。注意,空提交被注释掉了

编辑合约规则,主要看最上面的分支,编辑前你会看到很多的pick xxx这样的数据,第一个就是最后合并的分支,不动,后面的分支都改成s(即表示需要合并的分支)
TIPS:编辑时先按c进入编辑模式,编辑完成之后,按ESC退出,输入:wq 保存并退出,保存并退出之后会进入下一个编辑界面,一样保存并退出即可

4、强制提交

git push -f

强制提交至远程即可

5、可能遇到的问题

如果意外退出这个合并,可以使用下面的命令清除合并,重新开始合并操作

git rebase --abort
赞(23)
版权属于:

EYblog - Powered by Eyblog

本文链接:

https://www.jwwey.com/index.php/archives/94/(转载时请注明本文出处及文章链接)

评论 (0)
郑先森灬
世上没有偶然,有的只是必然,正面面对困难,才能迈向成功。
25 文章数
161 评论量

人生倒计时

今日已经过去小时
这周已经过去
本月已经过去
今年已经过去个月