我如何将最后的N承诺集成到一个承诺中?
当前回答
如果您想将每个承诺分成一个单一承诺(例如第一次公开发布项目时),请尝试:
git checkout --orphan <new-branch>
git commit
其他回答
在问题上,可以是双重的“最后”是什么意思。
* commit H0
|
* merge
|\
| * commit B0
| |
| * commit B1
| |
* | commit H1
| |
* | commit H2
|/
|
可以使用折扣,但以不同的方式,然后在其他提到的答案:
首頁 / 首頁 / 2
这将向您展示选择选项(如其他答案中提到的):
pick B1
pick B0
pick H0
pick B1
pick B0
s H0
在保存和退出后,将执行命令,然后在H1之后,这意味着它将要求你重新解决冲突(在那里,主将是H1首先,然后积累命令,当它们被应用)。
退缩结束后,您可以选择失败的 H0 和 B0 消息:
* commit squashed H0 and B0
|
* commit B1
|
* commit H1
|
* commit H2
|
P.S. 如果你只是做一些重新设置到BO:(例如,使用重新设置 - 混合,这里详细解释 https://stackoverflow.com/a/18690845/2405850):
git reset --mixed hash_of_commit_B0
git add .
git commit -m 'some commit message'
例如,如果您想在一个分支(远程存储库)中排除最后3个承诺,例如: https://bitbucket.org
我所做的就是
git reset --soft HEAD~3 git commit git push 起源 <branch_name> --force
git rebase -i HEAD^^
在哪里 ^'s 的数量是 X
(此分類上一篇: 最後兩個命令)
只需将此 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'
你已经完成了。
让我们说 n 真的很大. 你不想处理每一个承诺. 你只是想要一个名为 new_feature_branch 的新分支,其中有 1 承诺和所有旧_feature_branch 的变化。
git checkout main
# will contain changes all changes from old_feature_branch
git checkout -b new_feature_branch
# get all changes from old_feature_branch and stage them
for f in $(git --no-pager diff --name-only old_feature_branch ) ; do git checkout fencing -- $f ; done
git commit -m "one commit message"
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的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之间的区别