0

Honestly, I have always picked both and it has worked out so far. But I do not know in which concrete cases it would be better to pick one over the other. It would be good to see examples.

I tried using the ? to invoke help but reading it was not fruitful.

Thanks!

1

1 Answer 1

2

I assume you already know the difference:

  • index: staged diff
  • worktree: unstaged diff
  • both: both

As for examples, I'm not sure if this is a good one, but at times I use this feature:

Suppose you are debugging using the GOAT debugger: print. And suppose after 10 print you've found the bug. Now your files have become:

void a() {
    cout << __LINE__ << endl;
    cout << __LINE__ << endl;
    cout << __LINE__ << endl;
}

void b() {
    cout << __LINE__ << endl;
    cout << __LINE__ << endl;
    cout << __LINE__ << endl;

    // .......
    // .......
    // .......
    bug_fix();
    // .......
    // .......
    // .......
    // .......
    cout << __LINE__ << endl;
    cout << __LINE__ << endl;
    cout << __LINE__ << endl;
}

Then you stage your bug fix, now git status has become:

unstaged:
   modified:
      + cout << __LINE__ ....
      + cout << __LINE__ ....
      + cout << __LINE__ ....
      + cout << __LINE__ ....


      + cout << __LINE__ ....
      + cout << __LINE__ ....
      + cout << __LINE__ ....



      + cout << __LINE__ ....
      + cout << __LINE__ ....
      + cout << __LINE__ ....

staged:
    modified:
      + bug_fix();

And now, you wanna compile with bug_fix but without prints, and at the same time you realize, these prints prove useful in your debugging session and you wanna preserve these lines for your future debugging sessions. So you hit stash worktree. This way, your bug fix is staged; prints are gone and preserved in your stashes for future usage. And you are ready to test one last time before committing your bug fix.

stash index would take some effort to come up with a good example. I have reasonable (subjectively speaking) use case sometime ago, but I wouldn't think of that a good example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.