我如何将最后的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'
你已经完成了。
其他回答
这是超级可爱的,但在某种寒冷的方式,所以我只会把它推到戒指中:
GIT_EDITOR='f() { if [ "$(basename $1)" = "git-rebase-todo" ]; then sed -i "2,\$s/pick/squash/" $1; else vim $1; fi }; f' git rebase -i foo~5 foo
翻译:为 git 提供一个新的“编辑器”,如果要编辑的字体名称是 git-rebase-todo(互动的 rebase prompt) 会改变所有,但第一个“点”到“squash”,否则 spawns vim - 这样,当你被要求编辑破碎的承诺消息时,你会得到 vim。
也许我会做马克·隆加尔所建议的事情。
尝试了所有方法提到的这里. 但最终我的问题解决了通过遵循这个链接. https://gist.github.com/longtimeago/f7055aa4c3bba8a62197
$ git fetch upstream
$ git checkout omgpull
$ git rebase -i upstream/master
< choose squash for all of your commits, except the first one >
< Edit the commit message to make sense, and describe all your changes >
$ git push origin omgpull -f
基于这篇文章,我发现这个方法对我的使用更容易。
我的“dev”分支在“起源/dev”前面有96个承诺(因此这些承诺尚未推到远程)。
我宁愿将分支重新设置为“起源/dev”状态(这将使96个分支的所有变更无效),然后立即进行变更:
git reset origin/dev
git add --all
git commit -m 'my commit message'
您可以使用 git merge --squash 为此,这比 git rebase -i 略有优雅。
警告: 首先,请确保您完成工作 - 检查 git 状态是干净的(因为 git 重新设置 - 硬将抛弃错误和错误的变化)
然后:
# Reset the current branch to the commit just before the last 12:
git reset --hard HEAD~12
# HEAD@{1} is where the branch was just before the previous command.
# This command sets the state of the index to be as it would just
# after a merge from that commit:
git merge --squash HEAD@{1}
# Commit those squashed changes. The commit message will be helpfully
# prepopulated with the commit messages of all the squashed commits:
git commit
git merge 的文档详细描述了 --squash 选项。
更新:这个方法的唯一真正优点,比克里斯·约翰森(Chris Johnsen)在他的回答中提出的更简单的吉特重新设置 --soft HEAD~12 &&吉特承诺是,你会得到承诺的消息,以每一个承诺的消息,你正在破坏。
git rebase -i HEAD^^
在哪里 ^'s 的数量是 X
(此分類上一篇: 最後兩個命令)
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的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之间的区别