Giter VIP home page Giter VIP logo

Comments (5)

tarsius avatar tarsius commented on May 30, 2024

Magit automatically uses --index when it concludes that it is safe:

(defun magit-stash-apply (stash)
  "Apply a stash to the working tree.
If nothing is staged, then try to reinstate the stashed index.
Doing so is not possible if there are staged changes."
  (interactive (list (magit-read-stash "Apply stash")))
  (magit-run-git "stash" "apply" stash
                 (and (not (apply #'magit-anything-staged-p nil
                                  (magit-stashed-files stash)))
                      "--index")))

It doesn't do so when any of the affected files have staged changes, because when --index is used, then git stash apply automatically unstages all changes to those files, and if there are also unstaged changes to those files, then that state (which parts of those files are staged and which are not) would be lost. (Even if there are no unstaged changes, the "file is completely staged" state would be lost, though that might be less risky.)

We could refine the check performed by this command, to check whether there are both staged and unstaged changes. Maybe we could also/instead show a warning which informs the user about this complication.

from magit.

doublep avatar doublep commented on May 30, 2024

In my case there were absolutely no changes ­— staged or unstaged. The working directory was completely clean, yet the stash didn't apply. Again, as I don't really know what "index" is, I don't know how that is possible. But I have seen that myself.

from magit.

tarsius avatar tarsius commented on May 30, 2024

In my case there were absolutely no changes ­— staged or unstaged. The working directory was completely clean, yet the stash didn't apply.

Then I'll have to look into it some more.

Again, as I don't really know what "index" is, I don't know how that is possible.

The "index" is the same thing as the "staging area".

from magit.

doublep avatar doublep commented on May 30, 2024

The "index" is the same thing as the "staging area".

Ah, so then the problem is reproducible when the stash contains conflicting staged changes:

#! /bin/sh

rm -rf /tmp/git-stash-index

mkdir -p /tmp/git-stash-index
cd /tmp/git-stash-index

git init -q

echo "bla bla bla" > file
git stage file
git commit -m 1

echo "foo" >> file
git stage file
git stash

echo "bar" >> file
git stage file
git commit -m 2

git status
echo ^^^

git stash apply "stash@{0}" --index

This doesn't involve Magit, but naturally Magit will also fail to apply the stash, as the underlying command it'd use fails itself.

from magit.

tarsius avatar tarsius commented on May 30, 2024

Further work is required to make it always possible to apply a stash, see stash-apply branch.

from magit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.