简体   繁体   English

Git将特征分支合并到母版后,会显示功能更改之外的更改

[英]Git merge of a feature branch to master shows changes outside of the feature change

I generally use the following steps: 我通常使用以下步骤:

  1. Create a feature branch. 创建一个功能分支。
  2. After the feature is developed, I merge master into feature branch to get it up to date with master. 开发功能后,我将master合并到Feature分支中以使其与master保持最新。
  3. Push those merged changes to the feature branch. 将这些合并的更改推送到功能分支。
  4. Finally, I merge the feature branch into master, to be picked up for release. 最后,我将功能分支合并到master中,以进行发布。

After step 4 if I see the commits in the 'master' branch one of them shows "Merge branch 'master' into ". 在第4步之后,如果我在'master'分支中看到提交,则其中一个显示为“将分支'master'合并为”。 This commit shows all the changes made by others while I was working on my feature. 该提交显示了我在使用功能时其他人所做的所有更改。 Which is fine but when I see this commit in master, it seems confusing and it shows huge commits. 很好,但是当我在master中看到此提交时,它似乎很混乱并且显示了巨大的提交。 These were commits to the feature branch. 这些是对功能分支的提交。 Why are they appearing in the master branch? 为什么它们出现在master分支中?

Is there a way to merge feature branch to master but also ensure that only the feature changes show in the master commit log? 有没有一种方法可以将功能分支合并到主分支,又可以确保仅特征更改显示在主提交日志中?

This is why you rebase. 这就是为什么要变基。 When you're ready to merge master into your branch to get the latest code from master, instead do git rebase master in your feature branch. 当您准备将master合并到分支中以从master获得最新代码时,请在功能分支中使用git rebase master This basically rolls back all your commits in your feature branch, gets the latest commits from master to "update" your feature branch, then replays your commits on top of those. 基本上,这将回滚功能分支中的所有提交,从主服务器获取最新的提交以“更新”功能分支,然后在这些之上重播您的提交。 This way when you finally merge your feature branch into master, you don't have a merge commit to begin with. 这样,当您最终将功能分支合并到master中时,就没有合并提交。

You can see a nice diagram explanation here . 您可以在此处看到一个不错的图表说明。

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

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