Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 994651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:36:25+00:00 2026-05-16T06:36:25+00:00

I have the following scenario: * ab82147 (HEAD, topic) changes * 8993636 changes *

  • 0

I have the following scenario:

* ab82147 (HEAD, topic) changes
* 8993636 changes
* 82f4426 changes
* 18be5a3 (master) first

I’d like to merge (non fast-forward) topic into master. This requires me to:

  • git checkout master
  • git merge --no-ff topic

But checking out master, and then merging topic into it causes git to change my working directory (although the final result is identical to the one before checking out master), and the problem I have with that is due to the size of our project, it takes about 30 minutes to build it (with IncrediBuild) although nothing really changed and it’s simply unbearable.

So what I would like to get is the following:

*   9075cf4 (HEAD, master) Merge branch 'topic'
|\  
| * ab82147 (topic) changes
| * 8993636 changes
| * 82f4426 changes
|/  
* 18be5a3 first

Without really touching the working directory (or at least cheating git somehow).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:36:25+00:00Added an answer on May 16, 2026 at 6:36 am

    Interesting! I don’t think there’s a built-in way to do this, but you should be able to fudge it using the plumbing:

    #!/bin/bash
    
    branch=master
    # or take an argument:
    # if [ $@ eq 1 ];
    #      branch="$1";
    # fi
    
    # make sure the branch exists
    if ! git rev-parse --verify --quiet --heads "$branch" > /dev/null; then
         echo "error: branch $branch does not exist"
         exit 1
    fi
    
    # make sure this could be a fast-forward   
    if [ "$(git merge-base HEAD $branch)" == "$(git rev-parse $branch)" ]; then
        # find the branch name associated with HEAD
        currentbranch=$(git symbolic-ref HEAD | sed 's@.*/@@')
        # make the commit
        newcommit=$(echo "Merge branch '$currentbranch'" | git commit-tree $(git log -n 1 --pretty=%T HEAD) -p $branch -p HEAD)
        # move the branch to point to the new commit
        git update-ref -m "merge $currentbranch: Merge made by simulated no-ff" "refs/heads/$branch" $newcommit
    else
        echo "error: merging $currentbranch into $branch would not be a fast-forward"
        exit 1
    fi
    

    The interesting bit is that newcommit= line; it uses commit-tree to directly create the merge commit. The first argument is the tree to use; that’s the tree HEAD, the branch whose contents you want to keep. The commit message is supplied on stdin, and the rest of the arguments name the parents the new commit should have. The commit’s SHA1 is printed to stdout, so assuming the commit succeeded, you capture that, then merge that commit (that’ll be a fast-forward). If you’re obsessive, you could make sure that commit-tree succeeded – but that should be pretty much guaranteed.

    Limitations:

    • This only works on merges that could have been a fast-forward. Obviously you’ll actually have to check out and merge (possibly in a clone, to save your build system) in that case.
    • The reflog message is different. I did this deliberately, because when you use --no-ff, git will actually force itself to use the default (recursive) strategy, but to write that in the reflog would be a lie.
    • If you’re in detached HEAD mode, things will go badly. That would have to be treated specially.

    And yes, I tested this on a toy repo, and it appears to work properly! (Though I didn’t try hard to break it.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.