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 8699973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:04:54+00:00 2026-06-13T02:04:54+00:00

I want to backport a specific commit from a master branch of a project

  • 0

I want to backport a specific commit from a master branch of a project to some older branch that was branched off it.
E.g. under “branchA”, /my/nice/path/MyClass.java” should receive changes made by a particular commit under “master”, to “/my/nice/refactored/file/path/MyClass.java”.
How do I achieve this “the right way”? (e.g. I can just copy over the changes manually and treat the change in “branchA” as a regular edit, but that doesn’t seem right)

In perforce, I could do integrate in a manner that would allow me to specify both paths, including the branches; what’s the git equivalent?

Thanks!

  • 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-06-13T02:04:55+00:00Added an answer on June 13, 2026 at 2:04 am

    I ended up doing something like this (doesn’t handle new files)

    COMMIT_TO_PORT=(commit hash)
    for f in `git show --pretty="format:" --name-only ${COMMIT_TO_PORT}`
    do
    PATH_UNDER_MASTER=$f
    PATH_UNDER_BRANCHA=(make branchA path out of $f)
    FILEID=(optional - extract file name or some other ID to preserve new-old files for reference if auto-generated conflicts are not clear)
    git show "${COMMIT_TO_PORT}:{$PATH_UNDER_MASTER}" > "new_${FILEID}"
    git show "${COMMIT_TO_PORT}~1:{$PATH_UNDER_MASTER}" > "old_${FILEID}"
    git merge-file $PATH_UNDER_BRANCHA "old_${FILEID}" "new_${FILEID}"
    # optional - open $PATH_UNDER_BRANCHA 
    unset FILEID PATH_UNDER_MASTER PATH_UNDER_BRANCHA
    done
    unset COMMIT_TO_PORT
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Want to run javascript function from parent window in child window Example I have
Want to open firefox from terminal at linux with firebug enabled // Terminal $
Want to verify that my understanding of how this works. Have a C++ Class
Want to check that my site map contains a page. Could just iterate through
Want to create an alarm application, that will play a music file at a
Want to extract the text value from a lookup table's column in a db.
Want to attach an Event Handler/Listener to some links using the delegate() method, but
want to share a link from my application in windows phone 7. Any one
Want to pause the multiple views from updating when Pause button is pressed In
I have an application that depends on a 3rd party open source project hosted

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.