Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

git merge - Git. How to update feature branch withour merging unneccessary commits?

Im a bit confused about these scenarios:

  1. I have a task.
    I create feature branch, make work here.
    And then I create Pull Request to release-test branch.
    In order to avoid conflicts, first I have to update my feature branch. So I have to merge release-test into feature.
    But in this case, in my Pull Request I will have a lot of merged commits which I don't want to have. I want only my feature branch commits in PR.
    What should I do in this situation?

  2. I pushed my feature branch and then conflict appears in PR. What are my next steps?
    I tried to revert to the last commit, made compare with release-test branch, then force push. Is this a good practice?

P.S. I'm using Intellij Idea if this would help

question from:https://stackoverflow.com/questions/65540727/git-how-to-update-feature-branch-withour-merging-unneccessary-commits

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

1 Reply

0 votes
by (71.8m points)

In order to avoid conflicts, first I have to update my feature branch. So I have to merge release-test into feature.

Don't: you should always merge from specific to integration branches, not the reverse.

  • Your feature branch is a specific branch (specific for a given task you are isolating in its own branch)
  • release-test is an integration branch (where multiple branches come to be merged)

If you need to update your feature branch compared to release-test, rebase it:

 cd /path/to/local/repo
 git switch feature
 git fetch
 git rebase origin/release-test
 # resolve potential conflict there
 git push --force

That will guarantee there won't be any conflict in your PR (automatically updated after the push --force), since your feature branch will only add new commits on top of the most recent remote release-test branch.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...