Comments (5)
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.
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.
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.
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.
Further work is required to make it always possible to apply a stash, see stash-apply
branch.
from magit.
Related Issues (20)
- auto-fill-mode is broken in commit messages when using in git-commit-major-mode HOT 8
- ssh password prompt not matched by regexps HOT 1
- magit-insert-remote-branches: Assertion failed: (equal branch (concat remote "/HEAD")) HOT 2
- Weird void-variable errors regarding magit-section-inhibit-markers HOT 5
- condition-case: Suffix magit-log:--*-order is not defined or autoloaded as a command (interaction with native compilation?))
- How to insert a tab char at the beginning of each file name line like magit 1.x do in status buffer?
- Missing documentation HOT 2
- Reported-by and other git trailers not added below commit message HOT 2
- Forbidden reentrant call of Tramp when creating a signed commit HOT 5
- Commit 1ab107a7 broke M-2 and likely other section-related commands HOT 2
- Symbol’s function definition is void: seq-keep HOT 21
- magit-blame-removal and magit-blame-reverse has some functionality swapped?
- Multiple commands crashes in Emacs 30.0.50 HOT 7
- Commit word-wrapping can result in discarded message. HOT 2
- "Applying patches" section repeats already applied patches as "to pick" HOT 4
- How to update? HOT 2
- void-variable alist-get displaying sections HOT 6
- Package-Requires header should be single line HOT 8
- Jump to pushremote-related sections in magit status buffer does not seem to work HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magit.