我如何将最后的N承诺集成到一个承诺中?
当前回答
首先,我知道我的功能分支和当前主分支之间的承诺数量。
git checkout master
git rev-list master.. --count
然后,我创建另一个基于我的功能分支的分支,保持我的功能分支无触。
最后,我跑
git checkout my-feature
git checkout -b my-rebased-feature
git checkout master
git checkout my-rebased-feature
git rebase master
git rebase head^x -i
// fixup/pick/rewrite
git push origin my-rebased-feature -f // force, if my-rebased-feature was ever pushed, otherwise no need for -f flag
// make a PR with clean history, delete both my-feature and my-rebased-feature after merge
希望能帮忙,谢谢。
其他回答
什么可能真的很方便: 找到你想在顶部滑动的承诺,说d43e15。
现在使用
git reset d43e15
git commit -am 'new commit name'
有人提到在 IntelliJ IDEA UI 上做得多容易:
转到 git 窗口 手动选择所有要融入一个的承诺. 右键单击 > Squash 承诺 > 编辑失败的承诺消息 点击左侧的分支名称 > 右键单击 > Push > Force Push
此分類上一篇
只需将此 bash 函数添加到.zshrc 文件的 bash。
# Squash last X commits with a Commit message.
# Usage: squash X 'COMMIT_MSG'
# where X= Number of last commits.
# where COMMIT_MSG= New commit msg.
function squash() {
if [ -z "${1}" -o -z "${2}" ]; then
echo "Usage: \`squash X COMMIT_MSG\`"
echo "X= Number of last commits."
echo "COMMIT_MSG= New commit msg."
return 1
fi
git reset --soft HEAD~"$1"
git add . && git ci -m "$2" # With 100 emoji
git push --force
}
然后跑
squash X 'New Commit Message'
你已经完成了。
程序1
(一)定义承诺短暂的哈希
# git log --pretty=oneline --abbrev-commit
abcd1234 Update to Fix for issue B
cdababcd Fix issue B
deab3412 Fix issue A
....
在这里,即使是 git log --oneline 也可以用来获得短暂的 hash。
# git rebase -i deab3412
....
pick cdababcd Fix issue B
pick abcd1234 Update to Fix for issue B
....
....
pick cdababcd Fix issue B
squash abcd1234 Update to Fix for issue B
....
# git log --pretty=oneline --abbrev-commit
1122abcd Fix issue B
deab3412 Fix issue A
....
# git push origin +master
程序2
首先,添加所需的文件
git add <files>
git commit --fixup=OLDCOMMIT
现在这个创建了一个新的承诺在头顶与 fixup1 <OLDCOMMIT_MSG>。
其次,下令下令下令下令下令下令下令下令下令下令下令下令。
git rebase --interactive --autosquash OLDCOMMIT^
在这里 ^ 意味着以前的承诺到 OLDCOMMIT. 这个 rebase 命令在一个编辑器(vim 或 nano)上打开了互动窗口,我们不需要做任何事情,只是保存和输出是足够的. 因为转移到此的选项将自动移动最新的承诺到旧的承诺旁边,并将操作转换为 fixup(相当于 squash)。 然后 rebase 继续完成。
程序3
如果需要将新的更改添加到最后的承诺方式 - 更改可以使用 git-commit。
# git log --pretty=oneline --abbrev-commit
cdababcd Fix issue B
deab3412 Fix issue A
....
# git add <files> # New changes
# git commit --amend
# git log --pretty=oneline --abbrev-commit
1d4ab2e1 Fix issue B
deab3412 Fix issue A
....
结论
如果您不关心承诺信息的承诺之间,您可以使用
git reset --mixed <commit-hash-into-which-you-want-to-squash>
git commit -a --amend
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别