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

  • SEARCH
  • Home
  • 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 8014237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:52:14+00:00 2026-06-04T19:52:14+00:00

Short version: I’ve got a master branch, which people are working on and committing

  • 0

Short version: I’ve got a master branch, which people are working on and committing to. Then I’ve got a branch off of master, call it foo which people are also working on and committing to. Periodically, I want to bring over some, but not all, of the changes from foo back to master. I would like some way for the history of master to be query-able for the presence and absence of commits from foo. This appears problematic. How do I do this?

Long version: Create an example git repo like this:

cd /tmp && mkdir gitrepo && cd gitrepo/ && git init
echo "Something shared" > myFile.txt && git add myFile.txt && git commit -m "Added myFile.txt to master"
git checkout -b foo master
echo "Something else shared" > anotherFile.txt && git add anotherFile.txt && git commit -m "Added anotherFile.txt to foo"
echo "Something specific to foo" > foochange.txt && git add foochange.txt && git commit -m "Added foochange.txt to foo"
echo "Something else shared again" > yetAnotherFile.txt && git add yetAnotherFile.txt && git commit -m "Added yetAnotherFile.txt to foo"
git checkout master
echo "Something specific to master" > masterchange.txt && git add masterchange.txt && git commit -m "Added masterchange.txt to master"
echo "Specific to master" > masterchange.txt && git add masterchange.txt && git commit -m "Added masterchange.txt on master"

(All discussion from here forward assumes we’re on master)

Now we’ve got the situation where foo is two commits behind master and has three commits of it’s own. At this point I want to bring back the first and third commits from foo to master but NOT the second.

The fundamental issue is that the parent of the commit at the head of foo is the commit that I don’t want to merge, but since a commit’s parents are part of that commit’s hash there’s no way to preserve the hash of the commit at the head of foo without also creating a situation where git branch --contains foo^ is true for master.

For instance, if I did git merge foo it would merge all the commits from foo to master. After doing that I would be able to say git branch --contains foo^ and it would say that both foo and master contain that commit. I tried then doing a git revert foo^ but git branch --contains foo^ still reports that master contains foo^.

If I git cherry-pick foo foo^^ the two relevant revisions, then I have the changes from those two revisions’ diffs from foo applied in master, but git branch --contains foo^ says that only branch foo contains that commit.

What I’m trying to achieve here is some way to query the history (without manually correlating hashes stored as text in commit messages) so I can be able to see which commits have and haven’t been merged into master. As mentioned, I know of several ways to get the state of master to be equivalent to what I want (cherry-pick, merge+revert, format-patch/am, diff/patch, etc.) what I’m looking for is some way to query the history for the information I need. I get that git branch --contains will probably not ever work in the way I want it to, but if there’s some alternate way to query the history, that I haven’t thought of, I’m all ears.

Anyone have any ideas?

  • 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-04T19:52:17+00:00Added an answer on June 4, 2026 at 7:52 pm

    I think git-cherry is the command you are looking for.

    git cherry -v master foo
    

    This shows commits in foo that have not (yet) been merged into master.

    $ git cherry -v master foo
    + 1cffcfb1d061d308e8d33c262e30282a26b195cb Added anotherFile.txt to foo
    + fe0599190a6953c970cd3f94e18ff0c282e89e2c Added foochange.txt to foo
    + 1b548eb45ff50e59f3522ee63edd0c177e842645 Added yetAnotherFile.txt to foo
    
    $ git cherry-pick 1cffcfb1d061d308e8d33c262e30282a26b195cb
    ...
    
    $ git cherry-pick 1b548eb45ff50e59f3522ee63edd0c177e842645
    ...
    
    $ git cherry -v master foo
    - 1cffcfb1d061d308e8d33c262e30282a26b195cb Added anotherFile.txt to foo
    + fe0599190a6953c970cd3f94e18ff0c282e89e2c Added foochange.txt to foo
    - 1b548eb45ff50e59f3522ee63edd0c177e842645 Added yetAnotherFile.txt to foo
    

    From the manual:

    The ones that have equivalent change already in the upstream branch
    are prefixed with a minus (-) sign, and those that only exist in the
    head branch are prefixed with a plus (+) symbol:

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

Sidebar

Related Questions

Short Version: When I've created a Channel using ChannelFactory on a client which uses
Short version Need to distribute nightly builds to 70+ people each morning, would like
Short version: Say I have a string str and a file functions.py from which
Short version: I have a Qt/C++ to which I am having to add a
Short version: This prints 3, which makes sense because in Go strings are basically
Short version : echo testing | vim - | grep good This doesn't work
Short version: I have a similar setup to StackOverflow. Users get Achievements. I have
Short version: Is it easy/feasible/possible to program modal window in Flash (AS3)? Is there
Short version: I'm trying to determine the best way to track what the user
Short version: How can I map two columns from table A and B if

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.