I created feature branch from main develop
branch called my-feature
there is also another feature branch created by another developer another-feature
.
We both are doing changes in different files
Another developer already create PR but, not merged yet to develop. But, I need his changes to my branch so, I did git merge another-feature
to my my-feature branch and create Pull request.
But, main problem is now, I can see changes of another-feature
branch to my Pull request of my-feature
. So, how can I rebase that? I don't want to show changes from another branch.
I checked another post but, some of them are less understandable to me.
Any help would greatly appreciated.
Edit:
git log
Display like following. (Target branch is develop
)
commit: f0fdfddsdsde
Author: Me (As my last commit before creating PR)
Date: blah blah
commit message....
commit: a4dsdsdssdds
Author: Another developer (whose changes I merged)
Date: blah blah
commit message....
rest of another commits ....
git log ––all ––decorate ––oneline ––graph
f0acaed (HEAD -> feature/my-feature, origin/my-feature) commit message..
a4f4dab (origin/another-feature, feature/another-feature) commit message..
* db30503 (origin/HEAD, origin/develop, develop) merge pull request from another branch
blah blah blah
The changes will be visible on your PR unless the another-feature
is merged.
If you just want to not see those changes in your PR while reviewing, just change the base branch during the review (if the version control system you're using, allows that).
Another solution (that I prefer) is to rebase your branch
with another-feature
instead of merging them.
In this case you'll have less headache when the another feature is merged, and also while reviewing you'll be able to just review the commits that you've pushed (most of the systems allow you to select the set of commits while reviewing).
Update: (for the second approach mentioned above)
In order to jump to the original state of my-feature
, you'l need to use reflog
.
Here's how to do that.
git status
git reflog
and you'll see something like this:
There you can see the history of the head references. Just find the commit that was before the merge (in the picture it's the one with HEAD@{1}
with commit hash e919ec6
).git checkout HASH_HERE
(e.g. git checkout e919ec6
)checkout -b my-feature.ORIGINAL
Now the my-feature.ORIGINAL
contains your branch state before merging and you're on that branch.
In order to do rebase instead of merge, follow these steps:
git branch my-feature.BKP
git rebase another-feature
git rename my-feature my-feature.BAD
git rename my-feature.ORIGINAL my-feature