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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:10:01+00:00 2026-05-17T23:10:01+00:00

I totally love git add -p and git stash but I occasionally have the

  • 0

I totally love git add -p and git stash but I occasionally have the following problem, which is reproduced by the following sequence of commands:

  • git add -p my_file: then I edit a hunk manually (using e) because the splitting that git suggests does not suit me
  • git stash --keep-index: then I do some testing, and if the tests pass I do not commit
  • git stash pop: now the problem occurs: the file my_file is now considered as conflicted, and git has completely messed with my edited hunk, so I have to edit the file, remove the useless merge marks, and run git add my_file followed by git reset HEAD

I’m puzzled because this happens only when editing a hunk manually. I don’t see how this should make any difference at all.


To reproduce the problem:

  • touch newfile
  • git add newfile
  • git commit -m 'newfile'
  • add two lines in the file
  • git add -p newfile
  • edit the hunk (e), remove one of the line in the hunk, then quit git add (q)
  • git stash --keep-index
  • git stash pop

Now the file newfile is in unmerged state. Note, again, that the problem only occurs with manually edited hunks. There is no problem whatsoever with the commands above if one does not edit any hunk manually.

Incidentally, the preceding state of the file is in the third stage (git show :3:newfile), and the previously staged version is in the second stage (git show :2:newfile). So I could, by some git black magic, manage to put the second stage in this index, and the third stage in the working repo… but I don’t know how to do that so I do it by hand. 🙁

  • 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-17T23:10:02+00:00Added an answer on May 17, 2026 at 11:10 pm

    I asked the question in the git mailing list. What I describe is the expected behaviour. It’s not a bug. 🙁

    Here is the answer I got:

    If you did not edit the hunk manually, each hunk will be either in
    state HEAD or in state A, and applying the diff between HEAD and A to
    such file will be either a no-op (hunk already applied), or a
    successfull application.

    For me this is a severe limitation of git add --patch, and I don’t understand in what way this behaviour may be useful to anyone, but I will learn to live with it.

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

Sidebar

Related Questions

No related questions found

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.