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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:24:26+00:00 2026-06-04T16:24:26+00:00

I have a few questions about Grit/Git that I hope you can help me

  • 0

I have a few questions about Grit/Git that I hope you can help me with. Here’s my code:

# create Repo
r = Repo.init_bare 'myrepo.git'
i = r.index

# first commit to master
i.add('myfile.txt', 'my file contents')
i.commit("This is my commit")

# second commit to master
i.read_tree("master")
i.add('myfile2.txt', 'my file 2 contents')
i.commit("This is my second commit", [r.commits.first])

# first commit to newbranch
i.read_tree("master")
i.add('myfile3.txt', 'my file 3 contents')
i.commit("This is my third commit", [r.commits.first], nil, nil, 'newbranch')

# second commit to newbranch
i.read_tree("newbranch")
i.add('myfile4.txt', 'my file 4 contents')
i.commit("This is my fourth commit", [r.commit("newbranch")], nil, nil, 'newbranch')

With this code I’m trying to create a repo, commit twice to master, create a new branch from master, and commit twice to this branch. But the problem is that when I do this:

r.commits("newbranch")  # => 3

It says that there’s only 3 commits on “newbranch”. It leaves out the second commit on master. Why is that? Is there something wrong with my code?

The thing I’m most confused with is how to specify the parent commit when branching out, and when making the second commit on the “newbranch”.

Hope you can help. 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-04T16:24:28+00:00Added an answer on June 4, 2026 at 4:24 pm

    For now, this is my solution committing to a specific branch:

    index = repo.index
    index.read_tree( branch )
    index.add( path_to_a_file, file_data )
    c = repo.commits( branch ) 
    index.commit( comment, repo.commits( branch ), nil, nil, branch )
    

    The last line is allowing to commit to a specific branch without checking it out. Also, call to read_tree function is required, unless you don’t want to lose your index.

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

Sidebar

Related Questions

I have few questions about jQuery DataTables: How can i do that arrow next
I have a few questions about endian-ness that are related enough that I warrant
I just have a few general questions about keeping code clean and readable. 1)
I have few questions about this code: <?php $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv =
I have a few questions about screen resolution, that I'm not clear on. These
I learning to use Pointers. I have a few questions about an exercise code
I have few questions about https in Scala Lift: How can I set for
I have few questions about the capability of SSIS package. I want to create
I have a few questions about git. I have read a couple of documents
I'm learning ruby and have a few questions about some code I wrote for

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.