lib
lib

Reputation: 2956

Git merge to a old point in history

I have a small repository, which I try to keep the more linear as possible (only one main branch). At some point in time I introduced breaking change in my code, put a tag at that point and continue.

Now, after a lot of commits and push and pull, I needed to extract some stuff from the old code. I checked out a new branch from an old commit, added a new folder with some auxiliary script (didn't change existing code) and commited to this branch.

I would like to merge again this branch in the main branch, instead of having a dangling dead branch. The problem is that I would like to merge it before the tag of the breaking change (these new script would break with the code in HEAD). Is it possible?

I read also about rebasing, but I am concerned because I've alredy pushed and pulled the newer commits.

Upvotes: 2

Views: 560

Answers (1)

VonC
VonC

Reputation: 1324258

Yes, you can do (using the merge strategy ours):

git checkout master
git merge -s ours dead_branch

The dead_branch will be considered as merged in master, but none of dead_branch file will appear in (or modify any file of) master.
No need to merge "before" the tag. You merge the branch (and its scripts), except the changes introduced by that branch won't be reflected in master.

ours

This resolves any number of heads, but the resulting tree of the merge is always that of the current branch head, effectively ignoring all changes from all other branches.
It is meant to be used to supersede old development history of side branches.

Note that this is different from the -Xours option to the recursive merge strategy.

Upvotes: 2

Related Questions