4

Inside of Git Tower I have a stash of about 26 files. However, when I try to apply the stash back onto my working tree, I get an error about trailing whitespaces.

How can I apply the stash sucessfully, getting around that error?

Here's the full error message:

<stdin>:87: trailing whitespace.
       // query code
      <stdin>:88: trailing whitespace.
      // query code
      <stdin>:104: trailing whitespace.
        // query code   
      <stdin>:118: trailing whitespace.
        // query code
       <stdin>:119: trailing whitespace.
            //error code
error: patch failed: app/Http/Controllers/ProjectController.php:43
error: app/Http/Controllers/ProjectController.php: patch does not apply 
error: patch failed: resources/views/projects/filter.blade.php:1
error: resources/views/projects/filter.blade.php: patch does not apply
Conflicts in index. Try without --index.
poke
  • 369,085
  • 72
  • 557
  • 602
user3732216
  • 1,579
  • 8
  • 29
  • 54
  • Trailing whitespace is usually a *warning* that is printed by Git itself but which has no effect on the actual action that is being performed. Are you sure that your stash was unsuccessful? – poke Feb 21 '18 at 22:15
  • Yes because I don't get anything in my working tree as changed files. – user3732216 Feb 21 '18 at 22:23
  • I've updated my post to show the full error. – user3732216 Feb 21 '18 at 22:26
  • Well, that output is not about the whitespace but instead a conflict while trying to apply the patch. – poke Feb 21 '18 at 22:33

2 Answers2

4

Conflicts in index. Try without --index.

This means that you tried git stash apply --index and there were conflicts while Git tried to apply the stashed patch. When Git encounters conflicts, the conflicting state is stored in the index, to prevent you from accidentally committing unresolved conflicts and to remind you to actually solve those conflicts first. Thus, explicitly restoring the stashed index state will fail when Git would need the index for those conflicts.

This is also explained in the documentation:

If the --index option is used, then tries to reinstate not only the working tree’s changes, but also the index’s ones. However, this can fail, when you have conflicts (which are stored in the index, where you therefore can no longer apply the changes as they were originally).

So the solution, as the error message suggests, is to use the command without --index.

If Git Tower automatically does that for you, then you might have to restore the stash from the command line here.

poke
  • 369,085
  • 72
  • 557
  • 602
1

To add to the correct answer from poke : In Tower you have to deactivate the option "Restore Staging Area Status" to achieve applying the stash without --index.

Gerriet
  • 1,302
  • 14
  • 20