注意事项:rebase 改变分支的根源,绝对不要在与其他人共享的分支上进行操作rebase黄金法则:绝不要在公共的分支上使用它!
在项目中经常使用git pull来拉取代码,git pull相当于是git fetch + git merge;
在项目中运行git pull -r,也就是git pull --rebase,相当于git fetch + git rebase;
$git rebase master
可以看到rebase的操作,打乱了时间线;版本树形成一条
usage: git rebase [-i] [options] [--exec <cmd>] [--onto <newbase> | --keep-base] [<upstream> [<branch>]]
or: git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] --root [<branch>]
or: git rebase --continue | --abort | --skip | --edit-todo
--onto <revision> rebase onto given branch instead of upstream
--keep-base use the merge-base of upstream and branch as the current base
--no-verify allow pre-rebase hook to run
-q, --quiet be quiet. implies --no-stat
-v, --verbose display a diffstat of what changed upstream
-n, --no-stat do not show diffstat of what changed upstream
--signoff add a Signed-off-by trailer to each commit
--committer-date-is-author-date
make committer date match author date
--reset-author-date ignore author date and use current date
-C <n> passed to ‘git apply‘
--ignore-whitespace ignore changes in whitespace
--whitespace <action>
passed to ‘git apply‘
-f, --force-rebase cherry-pick all commits, even if unchanged
--no-ff cherry-pick all commits, even if unchanged
**--continue continue**
--skip skip current patch and continue
--abort abort and check out the original branch
--quit abort but keep HEAD where it is
** --edit-todo edit the todo list during an interactive rebase**
--show-current-patch show the patch file being applied or merged
--apply use apply strategies to rebase
-m, --merge use merging strategies to rebase
-i, --interactive let the user edit the list of commits to rebase
--rerere-autoupdate update the index with reused conflict resolution if possible
--empty <{drop,keep,ask}>
how to handle commits that become empty
--autosquash move commits that begin with squash!/fixup! under -i
-S, --gpg-sign[=<key-id>]
GPG-sign commits
--autostash automatically stash/stash pop before and after
-x, **--exec <exec> add exec lines after each commit of the editable list**
-r, --rebase-merges[=<mode>]
try to rebase merges instead of skipping them
--fork-point use ‘merge-base --fork-point‘ to refine upstream
-s, --strategy <strategy>
use the given merge strategy
-X, --strategy-option <option>
pass the argument through to the merge strategy
--root rebase all reachable commits up to the root(s)
--reschedule-failed-exec
automatically re-schedule any `exec` that fails
--reapply-cherry-picks
apply all changes, even those already present upstream
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit‘s log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with ‘git rebase --continue‘)
# d, drop <commit> = remove 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
# . specified). Use -c <commit> to reword the commit message.
#
# 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.
变基时可用的命令:pick,reword,edit,squash,fixup,exec
$git rebase -i HEAD~2
接着,git给你一个文本,告诉你我知道了,下面注释的是提示,我们不需要管,只要专注前两行就ok
接着 Esc,:wq 保存退出
$ git rebase -i HEAD~2
git rebase -i HEAD~2
接着 Esc,:wq 保存退出
【此种操作顺带的也会改变commit ID号】
git rebase -i HEAD~2
#使用“git rebase——edit-todo”查看和编辑
use "git rebase --edit-todo" to view and edit
You are currently editing a commit while rebasing branch ‘rebase_i‘ on ‘9119c19‘.
#您当前正在编辑提交,同时重新建立分支
#使用"git commit——amend"修改当前提交
use "git commit --amend" to amend the current commit
#当你对你的更改感到满意时,使用“git rebase——continue”
use "git rebase --continue" once you are satisfied with your changes
可参见上述操作步骤进展至11.4.1.3rebase_i分支多了REBASE-i 1/2,11.4.1.6使用"git commit——amend"修改当前提交
$ git rebase --continue
修改为
开始执行变更然后 在弹出来的编辑框里 写提交信息,可以修改提交消息,默认是把两个消息都合并
接着 Esc,:wq 保存退出,git log查看,合并成功
======================================================================
创作不易,本人热衷开源共享 《git rebase(变基)操作演示》
======================================================================
转载请附上链接:
https://www.cnblogs.com/cndevops/p/14993331.html
原文:https://www.cnblogs.com/cndevops/p/15010542.html