问题描述
我有一个远程Git服务器,这里是我想要执行的场景: 对于每个bug /特性我创建了一个不同的Git分支 我继续在该Git分支中使用非官方Git消息提交代码 在顶层存储库中,我们必须对官方Git消息中的一个错误进行一次提交。
说你的错误修复分支叫做 bugfix ,并且你想把它合并到 master $ c
$ b $ pre $ g $ c $ git checkout master
git merge --squash bugfix $ b $ git commit
这将从 bugfix 分支提交所有提交,将它们压缩为1次提交,并将其与您的 master 分支合并。
说明:
git checkout master
切换到您的 master 分支。
git merge --squash bugfix
接受来自 bugfix 分支的所有提交,并将其与您当前的分支合并。
git commit
从合并的更改中创建单个提交。
省略 -m 参数可让您在完成提交之前修改草稿提交消息,其中包含压缩提交中的每条消息。
I have a remote Git server, here is the scenario which I want to perform:
For each bug/feature I create a different Git branch
I keep on committing my code in that Git branch with un-official Git messages
In top repository we have to do one commit for one bug with official Git message
So how can I merge my branch to remote branch so that they get just one commit for all my check-ins (I even want to provide commit message for this)?
Say your bug fix branch is called bugfix and you want to merge it into master:
git checkout master git merge --squash bugfix git commit
This will take all the commits from the bugfix branch, squash them into 1 commit, and merge it with your master branch.
Explanation:
git checkout master
Switches to your master branch.
git merge --squash bugfix
Takes all the commits from the bugfix branch and merges it with your current branch.
git commit
Creates a single commit from the merged changes.
Omitting the -m parameter lets you modify a draft commit message containing every message from your squashed commits before finalizing your commit.
这篇关于如何使用git merge --squash?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!