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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:53:27+00:00 2026-05-14T00:53:27+00:00

It’s kind weird, but I can’t fulfill a pretty common operation with git. Basically

  • 0

It’s kind weird, but I can’t fulfill a pretty common operation with git. Basically what I want is to checkout a feature branch, not using it’s head but using SHA id. This SHA points between merges from master branch.

The problem is that all I get is just master branch without a commits from feature branch.
Currently I’m trying to fix a regression introduced earlier in master branch.

Just to be more descriptive, I crafted a small bash script to recreate a problem repository:

#!/bin/bash

rm -rf ./.git
git init

echo "test1" > test1.txt
git add test1.txt
git commit -m "test1" -a

git checkout -b patches master

echo "test2" > test2.txt
git add test2.txt
git commit -m "test2" -a

git checkout master

echo "test3" > test3.txt
git add test3.txt
git commit -m "test3" -a

echo "test4" > test4.txt
git add test4.txt
git commit -m "test4" -a

echo "test5" > test5.txt
git add test5.txt
git commit -m "test5" -a

git checkout patches
git merge master    

#Now how to get a branch having all commits from patches + test3.txt + test4.txt - test5.txt ???

Basically all I want is just to checkout branch “patches” with files 1-4, but not including test5.txt.

Doing:
git checkout [sha_where_test4.txt_entered]

… just gives a branch with test1,test3,test4, but excluding test2.txt

More complex example:

#!/bin/bash

rm -rf ./.git
git init

echo "test1" > test1.txt
git add test1.txt
git commit -m "test1" -a

git checkout -b patches master

echo "test2" > test2.txt
git add test2.txt
git commit -m "test2" -a

git checkout master

echo "test3" > test3.txt
git add test3.txt
git commit -m "test3" -a

echo "test4" > test4.txt
git add test4.txt
git commit -m "test4" -a

echo "test5" > test5.txt
git add test5.txt
git commit -m "test5" -a

git checkout patches
git merge master

echo "test6" > test6.txt
git add test6.txt
git commit -m "test6" -a

#Now how to get a branch having all commits from patches + test3.txt + test4.txt - test5.txt ???
git log --topo-order | cat

# Now I need something to help me going back to history 
# without manually calculating that patches~2 sha's
git checkout -b patches.tmp master~1
git merge patches~2

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-05-14T00:53:27+00:00Added an answer on May 14, 2026 at 12:53 am

    Regarding your first example, you need to replay test3 and 4 on top of test2: this is a classic case of rebase --onto:

    Start from:

    alt text http://img169.imageshack.us/img169/2255/gitr1.png

    Mark the current patches emplacement, and move the patches branch where you would like to end (test4):

    C:\Prog\Git\tests\rep\main>git checkout patches
    Switched to branch 'patches'
    
    C:\Prog\Git\tests\rep\main>git checkout -b tmp
    Switched to a new branch 'tmp'
    
    C:\Prog\Git\tests\rep\main>git checkout patches
    Switched to branch 'patches'
    
    C:\Prog\Git\tests\rep\main>git reset --hard master~1
    HEAD is now at 8448d0f test4
    

    That gives you:

    alt text http://img169.imageshack.us/img169/4826/gitr2.png

    And just rebase onto what you want the correct sequence of commits:

    C:\Prog\Git\tests\rep\main>git checkout tmp
    Switched to branch 'tmp'
    
    C:\Prog\Git\tests\rep\main>git rebase --onto tmp tmp~1 patches
    First, rewinding head to replay your work on top of it...
    Applying: test3
    Applying: test4
    

    Which gives:

    alt text http://img52.imageshack.us/img52/372/gitr3.png

    That only works for linear set of commits to be moved around.

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

Sidebar

Ask A Question

Stats

  • Questions 345k
  • Answers 345k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can compile and invoke a lambda expression whose body… May 14, 2026 at 5:52 am
  • Editorial Team
    Editorial Team added an answer Is there a way to limit a regex to 100… May 14, 2026 at 5:52 am
  • Editorial Team
    Editorial Team added an answer Once you create your behavior to set the focus, you… May 14, 2026 at 5:52 am

Related Questions

Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I want use html5's new tag to play a wav file (currently only supported
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.