Merging a branch into an intermediate commit in GIT

468 views Asked by At

Say you have a separate branch which keeps getting new commits for tracking a database dump, and that it's a branch from the first commit of master.

I know I can merge into HEAD of master, the usual procedure.

Instead, I wanted to merge the branch history into an intermediate commit, for keeping parallel branch lines in gitk to a minimum.

So I tried to:

git checkout -b temp_master_branch [Intermediate master commit SHA1]
git merge db_dump_branch
git checkout master

Nevertheless, when I visualize in gitk there are now 3 long lines, one for master, another for the dump branch and finally other for this new temp_branch.

How can I do this ? I hope it makes some sense.

Thanks.

1

There are 1 answers

2
Magnus Bäck On BEST ANSWER

Merges always create new commits (except in the fast-forward case), so merging into an old commit isn't possible without creating a new branch or rewriting the existing branch. If you want the database dumps in your master branch you need to merge into the tip of the master branch and deal with how gitk looks.

Other options to attack the long-lived parallel branch:

  • Have the database dumper commit directly to master.
  • Unless updates are very frequent, have the dumper create a short-lived new branch for each dump.