简体   繁体   English

使用git merge --squash将master先前合并到dev中时将development合并到master中?

[英]Using git merge --squash to merge develop into master when master was previously merged into develop?

I have two branches. 我有两个分支。 My master branch and my feature branch. 我的主分支和我的功能分支。

I'm developing on the feature branch and did several commits there and pushed them to the remote. 我正在功能分支上进行开发,并在那里进行了几次提交,并将其推送到远程。 From time to time I merged the master branch into my develop branch to make sure that I get the newest changes. 我不时地将master分支合并到我的developer分支中,以确保获得最新的更改。

Now I'm done with developing on the develop branch and want to merge the develop branch into the master branch. 现在,我已经完成了develop分支上的开发工作,并希望将develop分支合并到master分支中。

Ideally, I would like to squash all commits on the develop branch into one single commit. 理想情况下,我想将develop分支上的所有提交压缩为一个提交。 I guess I could do that with 我想我可以做到

git merge --squash

However, can I still do that when I merged master into develop from time to time? 但是,当我不时将master合并到development中时,我仍然可以这样做吗?

You have merged master into develop from time to time - you mean to say you have updated the master branch and develop branch with the changes from master branch, in your local repo from time to time, correct? 您已不时将master合并到develop -是说您已不时在本地仓库中更新了master分支并使用master分支中的更改来develop分支,对吗?

In that case, when you do a git checkout develop and a git log , and if you are the only person who has been working on this branch , you should see only your commits till date - in which case you can directly do a git merge --squash develop , which will take all the commits made to develop branch and squash it into one. 在这种情况下,当您进行git checkout developgit log ,并且如果您是唯一在该分支上工作过的人,则应该只看到截止日期的提交-在这种情况下,您可以直接进行git merge --squash develop ,它将把develop分支所做的所有提交并git merge --squash develop到一个分支中。

If you have other people working on this develop branch too , and their commits are also in between yours, and you want to only squash your commits, then do a git rebase -i , where you can pick the commits you want to squash by replacing the word 'pick' before the corresponding commits with 'squash' . 如果您也有其他人在此develop分支上工作 ,并且他们的提交也在您之间,并且您只想压缩您的提交,则执行git rebase -i ,在其中您可以通过替换来选择要压缩的提交相应单词前面的单词'pick'带有'squash'

Or, you can follow the first method listed here . 或者,您可以按照此处列出的第一种方法进行操作。

The easiest way to turn multiple commits in a feature branch into a single commit is to reset the feature branch changes in the master and commit again, this time - everything as one. 将功能分支中的多个提交转换为单个提交的最简单方法是,重置主节点中的功能分支更改,然后再次提交-一切都作为一个。

If you use git merge develop --squash to merge develop branch into master , it won't squash commits to a commit on develop branch, but create a "merge commit" on master branch. 如果您使用git merge develop --squashdevelop分支合并到master ,它将不会将提交提交压到develop分支上,而是在master分支上创建一个“ merge commit”。 Illustrate by below graphs: 通过下图说明:

Assume the original commit history is (before merging develop into master ): 假设原来提交历史(合并前developmaster ):

A---B---F---G   master
     \
  …---C---D---E   develop

After you execute git merge develop --squash , the new commit H as if you do a real merge the changes from develop branch into master . 在执行git merge develop --squash ,新的提交H就像您进行真正的合并一样,将更改从develop分支更改为master

A---B---F---G---H   master
     \
  …---C---D---E   develop

And of cause you can merge master into develop and then merge develop branch back into master branch. 因此,您可以将master合并到develop ,然后将develop分支合并回master分支。 But it's not a recommend way. 但这不是推荐的方法。 You should treat only one branch as the main branch (such as master branch as main branch). 您应仅将一个分支视为主分支 (例如,将master分支视为主分支)。 When the other branch ( develop ) has new features/changes, you just need to merge develop into master branch. 当另一个分支( develop )具有新功能/更改时,您只需要将develop合并到master分支即可。 When other new changes committed on develop branch later, you just need to merge develop branch into master branch from time to time. 当稍后在develop分支上进行其他新更改时,您仅需要不​​时将develop分支合并到master分支中。

And if you only want to squash commits on develop branch, you can use git rebase -i develop~n , and then edit the commits you want to squash (change drop to squash ) in interactive window. 如果你只是想壁球犯下的develop分支,可以使用git rebase -i develop~n ,然后编辑要壁球(改变提交dropsquash在交互式窗口)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM