Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
226 views
in Technique[技术] by (71.8m points)

git - 如何使用git merge --squash?(How to use git merge --squash?)

I have a remote Git server, here is the scenario which I want to perform:

(我有一个远程Git服务器,这是我要执行的方案:)

  • For each bug/feature I create a different Git branch

    (对于每个错误/功能,我创建一个不同的Git分支)

  • I keep on committing my code in that Git branch with un-official Git messages

    (我继续在Git分支中使用非官方的Git消息提交代码)

  • In top repository we have to do one commit for one bug with official Git message

    (在顶级存储库中,我们必须使用官方Git消息对一个错误进行一次提交)

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)?

(那么,如何将我的分支合并到远程分支,以便他们对所有签入仅获得一次提交(我什至想为此提供提交消息)?)

  ask by SunnyShah translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Say your bug fix branch is called bugfix and you want to merge it into master :

(假设您的错误修复分支称为bugfix并且您希望将其合并到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.

(这将从bugfix分支中获取所有提交,将它们bugfix为1个提交,并将其与您的master分支合并。)


Explanation :

(说明 :)

git checkout master

Switches to your master branch.

(切换到您的master分支。)

git merge --squash bugfix

Takes all the commits from the bugfix branch and merges it with your current branch.

(从bugfix分支中获取所有提交,并将其与当前分支合并。)

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.

(省略-m参数,可以在最终提交之前修改包含已压缩提交中的每个消息的提交消息草稿。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...