Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Partial stage/unstage operations fail with cryptic error

Nathan Gray March 21, 2012

When I try to stage or unstage part of a file using the Stage Hunk or Stage Selected Lines button I get the following error:

'git apply' failed with code 1:'error: (null): does not exist in index

'

The last single quote appears on its own line.

I have tried running 'git fsck' on the repo and didn't get anything unusual.

17 answers

1 accepted

24 votes
Answer accepted
Jasmine Hegman October 10, 2012

Follow up, this is fixable by setting Show Whitespace to Ignore Whitespace. Then the apply works. It appears that some of the time the line numbers from whitespace changes affects things negatively. This doesn't always happen, but at least for me this time it fixed it. Hope it helps someone else! :)

Deleted user November 19, 2014

Still have this issue in 2014, but "Ignore Whitespace" helped. Thank you!

ollietreend March 27, 2015

Yep - this issue still exists, and this still seems to fix it. For those who aren't sure where the 'Show Whitespace' option is located - look for the small cog icon in the top right corner of the "File Status" view, to the right of the search box. The option is in there.

Ryan_Draper October 27, 2015

I found the reverse fixed my problem, setting from Ignore to Show. Whatever works I guess.

Like Sreeram Ramakrishnan likes this
Michael Cote January 26, 2016

its 2016 and this is still an issue...

s g January 26, 2017

Where is "setting Show Whitespace to Ignore Whitespace"?

RichH January 27, 2017

2017-01-27 16_50_08-SourceTree.png

s g January 28, 2017

OK, so that not helps.

RichH April 20, 2017

You're right, that didn't. Not sure what happened there. Let's try again.

Luv4sko

Petr Nagy June 11, 2020

With either Ignore whitespace or Show whitespace checked, this issue still exists in 2020. I'm sorry but how hard can it be to fix?

Like # people like this
4 votes
Simon Dingley January 11, 2015

The only way I could get around this was to stage all changes to file then unstage the chunks I didn't want to commit.

1 vote
Sreeram Ramakrishnan December 22, 2020

This is still an issue in December, 2020; disappointing to say the least!

Anyway, the fix for me was to switch to show instead of ignore.

1 vote
Carsten Wegner May 11, 2014

Might also be the character encoding. If you set encoding to e.g. UTF-8 in SourceTree, but save the file in ANSI and have e.g. german Umlaut characters in it. Make sure to use consistent whitespace, character encoding and line-end handling.

Johannes Luber October 6, 2014

I can confirm this. I merely changed the encoding for a file from ANSI to UTF-8 and now it works. Also I noticed that in ANSI, umlauts weren't shown correctly, merely as the question mark placeholder glyph.

1 vote
Jeremiah Small April 21, 2013

Switching to Ignore Whitespace fixed this for me.

Daniel Rice February 16, 2014

How do you switch to Ignore Whitespace?

Simon Dingley January 26, 2017

Above the diff view there is a cog icon, click that and you will see the option to show or ignore whitespace differences in the view.

1 vote
Joel Stein March 26, 2013

I'm getting this same problem when trying to "Stage Hunk". I don't know how to do the suggested fixes. Will somebody please enlighten me?

1 vote
Mark Turner July 16, 2012

I'm also having the same issue:

'git apply' failed with code 1:'error: attak_game.js: does not exist in index'

When trying to "Stage Selected Lines"

1 vote
Nathan Gray March 21, 2012

It fails on any file in any repo on my machine. Doing "git add --patch" works properly, as does using the equivalent feature in Tower.

Actually I just figured it out. This feature breaks if you have diff.mnemonicprefix set to true in your git config.

0 votes
Thomas Harold January 4, 2016

Try adding the following to your ~/.gitconfig

[apply]
    whitespace = nowarn
RichH April 20, 2017

Does this allow merges to complete successfully, or just suppress the error and cause the merge to mess your file up? :)

blueblau September 27, 2017

I tried the above, restarted my machine, and got this slightly different error...Skærmbillede 2017-09-27 kl. 09.11.59.png

0 votes
DimitryDushkin November 25, 2014

Problem still presents.(

blueblau September 26, 2017

Still... 5.5 years later.

0 votes
Joshua Marsh April 2, 2014

This thread is quite old, but I just wanted to stop in and say I still see this issue.

Gotta be line-ending-related; I'm attempting to stage hunks/selected lines on a Windows machine after the source files were last modified on a Unix machine.

Very irritating issue, and none of the fixes in this thread worked for me.

0 votes
Tai Lee March 23, 2014

I see this with "Ignore Whitespace" AND "Show Whitespace". I don't have "diff.mnemonicprefix" set in my gitconfig. As far as I can tell, my file just has UNIX style line endings. What's the cause and fix?

0 votes
fcorreia May 28, 2013

Despite the workaround, this is very annoying. Hope it get's fix really soon.

0 votes
Sebastian Siedentopf March 24, 2013

I see this when end-of-line characters are messed up in a file.

0 votes
Jasmine Hegman October 9, 2012

Just wanted to add that I too experience this occasionally. Got it now in a file with several different detected hunks, and none of then can work via apply hunk or apply selected lines, nor can they be un-applied. Only fully staging the file as a whole works.

0 votes
Dennis Cornwell July 1, 2012

I'm seeing the same error. Unfortunately, settng both my global and local diff.mnemonicprefix setting to false doesn't solve the problem for me.

0 votes
stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 21, 2012

Can you give some more details about the file you're trying to do this on? This functionality works in all my tests here.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events