Reputation: 2743
I was working on a big task on a my-branch
branch which was create out of develop
.
In the meantime, I was taking pulls from develop
, thinking it was a good one.
After some time the develop
branch was renamed to test
.
Other developers were informed to make tests on the test
branch.
I was informed that the develop
branch was renamed to test
, but I was not informed that I should start taking pulls (to merge) from master
.
Then I started taking pulls from master
.
Now my-branch
has a lot of my work (good one), and a lot of tests - bad ones that should not be merged to master.
I need to:
my-branch
all the commits that: are not mine && are not in master
In other words, I need to remove all the commits other did, and those commits were not merged with master
. This means those commits were tests/trash.
How to do that?
Upvotes: 0
Views: 34
Reputation: 30212
Perhaps this will work (assuming that your local master
/test
branches are already up-to-date with the remote ones):
git rebase --onto master test my-branch
This can be read like this: git, please, rebase all revisions that are on my-branch
on top of master
but make sure to discard all revisions that make up the history of test
branch..... thanks!
This should be rebasing only revisions of yours, unless you did something funky.
Alternatively, if you are able to come up with a list of commits from git log
that matches your requirements (log allows you to provide matching authors and being able to tell commits that should be excluded (^exclude-commits-from-this-branch-or-commit
) and included (the normal git log whatever
) so you can get a fancy list of commits like git log --author="somebody" --reverse --no-merges --pretty="%h" ^exclude-from-here ^also-from-here this-is-what-i-want-to-rebase > commits.txt
). Then, you can cherry-pick them with:
git checkout --detach master
while read commit; do
git cherry-pick $commit
if [ $? -ne 0 ]; then
echo There was an error cherry-picking $commit
break
fi
done < commits.txt
Upvotes: 1