(I've seen #1139, and I'm not sure my issue is the same. I poked through the
issues and didn't see anything that fixed my problem, so I'm sorry if this is
a dupe!)
I'm having a problem where I can't stage individual hunks with Magit. If I go
into diff mode and type s, it inevitably fails with
patch does not apply... [See buffer *magit-process* for details].
I'm running OS X (10.9.5), on Emacs 24.4.1 installed from homebrew.
M-x emacs-version gives me
GNU Emacs 24.3.1 (x86_64-apple-darwin, NS apple-appkit-1038.36) of 2013-03-13 on bob.porkrind.org.
I installed magit from melpa, my magit-version is
magit-20150124.930 (but the problem is present on the stable version too).
My git is also from homebrew, version 2.2.1.
Here are the steps I took to get the bug on a clean repo:
$ mkdir -p /tmp/git-test
$ cd /tmp/git-test
$ emacsclient -n junk.txt (I use graphical Emacs)
Here is a file.
```
One line.
Here is a file.
Two lines.
```
M-x magit status, highlightjunk.txt and type d. Diff mode opens, with this content:```
Changes from HEAD to working tree
1 file changed, 4 insertions(+)
junk.txt | 4 ++++
Modified junk.txt
diff --git a/junk.txt b/junk.txt
index f6b83c9..9969474 100644
--- a/junk.txt
+++ b/junk.txt
@@ -1 +1,5 @@
+one line.
+
here is a file.
+
+two line.
[back]
```
a to stage. Error message: junk.txt: patch
does not apply ...
[See buffer *magit-process* for details). Magit-process buffer looks like this
1 /usr/local/bin/git --no-pager -c core.preloadindex=true apply --ignore-space-change -
error: patch failed: junk.txt:1
error: junk.txt: patch does not apply
I'm not sure what else to do; I'm relatively new to Emacs, so let me
know if you need more information...thanks!
Press s to stage, not a. The latter applies a change to to working tree, which it cannot do here because the change already is in the working tree.
I tried s, but it doesn't work either: I just get the message Can't stage this hunk. magit-process doesn't have any helpful information in that case. Uppercase S stages the whole file (not the hunk).
mmcclimon: while not strictly relevant to the problem in diff mode, you do know that from the status buffer you can expand unstaged files with TAB and then stage hunks (or regions) with 's' ?
you do know that from the status buffer you can expand unstaged files with TAB and then stage hunks (or regions) with 's' ?
@phil-s: :+1:
No, I didn't realize that. Now that I do, though, I see that I was overlooking the relevant portion in the manual:
To move an unstaged hunk into the staging area, move point into the
hunk and type ‘s’. Likewise, to unstage a hunk, move point into it and
type ‘u’. If point is in a diff header when you type ‘s’ or ‘u’, all
hunks belonging to that diff are moved at the same time.Currently it is only possible to stage from the status buffer.
Staging and unstaging from diff buffers that show unstaged and staged
changes is not possible yet.
It's a little counterintuitive, but at least it's documented. I know the docs are being revised (#1096), so it might be worth adding a line or two about using <tab> to expand a file in the status buffer in the chapter on staging/committing. To me doing it in diff mode made sense, and that's why I was confused when it didn't work like I thought it would.
Most helpful comment
mmcclimon: while not strictly relevant to the problem in diff mode, you do know that from the status buffer you can expand unstaged files with TAB and then stage hunks (or regions) with 's' ?