我如何将最后的N承诺集成到一个承诺中?
当前回答
只需将此 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'
你已经完成了。
其他回答
什么可能真的很方便: 找到你想在顶部滑动的承诺,说d43e15。
现在使用
git reset d43e15
git commit -am 'new commit name'
如果您使用 TortoiseGit,您可以将函数结合到一个承诺:
打开 TortoiseGit 背景菜单 选择显示日志 标记日志视图中的相关任务 从背景菜单中选择组合到一个任务
此分類上一篇
此功能自动执行所有必要的单 git 步骤 不幸的是,仅适用于 Windows。
我如何将我的最后一个X承诺集成到一个使用Git的承诺?
git rebase -i HEAD~X
下列内容将显示:
pick 1bffc15c My earlier commit
pick 474bf0c2 My recent commit
# ...
对于你想要的承诺,请用 fixup 取代 pick,所以它会变成:
pick 1bffc15c My earlier commit
fixup 474bf0c2 My recent commit
# ...
如果它在 vim 中打开(终端内默认界面),然后按 Esc 在键盘上,输入 :wq 并输入以保存文件。
查看: 查看 git log
方法1 如果你有很多承诺
git rebase -i master 然后按一下键盘“i”来编辑
你会看到这样的:
pick etc1
pick etc2
pick etc2
用“f”取代“ pick”这个词,然后按 esc y :wq。
pick etc1 //this commit will the one commit
f etc2
f etc2
按下这个命令
git push origin +head
方法2 如果你有少数承诺,你可以这样做去删除承诺,你必须这样做去删除你的第二承诺等等。
git reset --soft HEAD^1 // or git reset --soft head~1
git commit --amend //then press `:wq`
git push -f
方法 3 如果你已经有一个承诺,你不想提交另一个承诺更多
git add files...
git commit --amend //then press `:wq`
git push origin +head
如果您正在与 GitLab 合作,您可以按下面的 Merge 请求中的 Squash 选项,承诺消息将是 Merge 请求的标题。
此分類上一篇
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的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之间的区别