这里写自定义目录标题
- 一、将当前改动追加到某次commit上
- 二、git 强制修改分支位置
一、将当前改动追加到某次commit上
- stash工作区中的当前改动
git stash
- 假设需要修改的commit是
f744c32
,将HEAD移动到需要改动的commit的父提交上git rebase f744c32^ --interactive
,找到需要更改的commit,将行首的 pick 改成 edit,保存退出。
注意这个
f744c32^
,表示f744c32
的父提交。这里有个前提:如果你想修改f744c32
这个提交本身,就需要rebase到它的父提交。假设提交历史如下:A - B - C - D(HEAD)
如果你想修改 B、C、D,用
git rebase B^ --interface
或git rebase A --interface
- 执行命令
git stash pop
- 使用
git add 改动的文件
将改动文件添加到暂存区 - 使用
git commit --amend
追加改动到第2步中指定的commit上 - 使用
git rebase --continue
移动HEAD到最新的commit处
第3步中 pick 变 edit和第5步如果产生冲突,都会使变基操作暂停。如果有冲突会在这一步体现出来,手动解决冲突后,再次执行git rebase --continue
即可完成rebase,以及针对目标commit的修改。 - 使用
git branch -f 分支名 HEAD
将本地分支强行切换到rebase后的头上。
备注:使用cat .git/HEAD
查看当前HEAD的指向
二、git 强制修改分支位置
git branch -f release_V6.5.0.0 HEAD~3
git branch -f release_V6.5.0.0 具体commit的哈希值