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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:46:15+00:00 2026-05-14T08:46:15+00:00

I just created a big piece of code I want to commit in several

  • 0

I just created a big piece of code I want to commit in several separate commits.
So I can stage relevant parts, commit, stage, commit, … and so on until I have all my changes commited.

The missing part is how can I test whether I split the commit correcty.
I.e. whether the part that is in staging area at least compiles?

To do that I must somehow bring my work tree to be in sync with index (staging area) without losing the changes to be committed later.

What is the right way to do it?
What is the quickest way to do it?

Update:
How to do it with magit?

  • 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-14T08:46:16+00:00Added an answer on May 14, 2026 at 8:46 am

    You could do it with:

    $ git branch task1 # first set of commit to do
    

    An intermediate branch can be useful to record some intermediate commits when you are slowly adding some content to the index.

    Then try an interactive session for adding just what you want:

    $ git add -i
    

    Add any time you want to check what you have added:

    $ git stash --keep-index
    

    If it compiles, git commit your current work, and if task1 is not yet complete, git stash pop to restore the full working tree and repeat.

    Once task1 is fully baked, you can trim all those ‘task1‘ commits, and merge the all work in master:

    $ git checkout master
    $ git merge task1
    $ git branch -D task1 # no need for that intermediate branch
    

    If you want to conserve the history of some significant task1 commits, you can rebase first task1 on top of master, before merging master in task1 (fast-forward)

    Finally, if your stash still contains some work in progress, repeat the all process for task2.

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

Sidebar

Related Questions

I want to mock a ResultSet. Seriously. I'm refactoring one big complicated piece of
I just created a project so my Solution Explorer looks like this: (source: kalleload.net
I just created a ASP.NET MVC project in VS2008. When I press F5 to
I've just created a new Windows XP VM on my Mac using VMware Fusion.
I've just created my first Preview 5 error and it doesn't seem to place
I’ve just created a WCF service/client and it all works fine when running on
Just starting out in asp.net. Have just created a login.aspx page in my site
I'm trying to debug the MSBuild Customtask, that I have just created, but for
If I have a datetime field, how do I get just records created later
I created a simple .NET windows application in Visual Studio 2005 and on just

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.