MAGIT: How to quickly see diff (changes) between current buffer/file and last commit of that same buffer/file? - diff

I have checked for similar questions but I couldn't find an updated one on MAGIT especifically.
My goal is to quickly visualize the diffs between the current file I am working on (just the file, not the whole folder/files in git) and the last commit of the same file, just to see the recent additions/deletions. What is the quickest way to do this? Thank you!

C-c M-g will pop up a menu just for that fie and you can hit d there to get a diff. Thanks #Dave F

Related

Programatically remove entry from Atom's undo stack

I've written a small piece of coffeescript code for Atom editor to update a timestamp comment on certain files just before they are saved, and it works perfectly.
Unfortunately, this modification ends up, obviously, on Atom's undo stack, so if after saving these files I undo my changes, the timestamp is undone before the previous changes. For this reason I want to remove this timestamp update from the undo stack.
I know I can pack multiple changes into a single undo transaction using TextBuffer.transact() or TextEditor.transact(), but I can't find how to just remove last entry (or entries) from the undo stack.
Is the only solution to access directly the historyProvider and mess with the undostack Array? Frankly, right now I don't know which side-effects this can have, but I don't find anything in Atom API todo what I need.
Thanks a lot in advance, as always :)
Sorry for the auto-answer, but I found a way of achieving what I want.
Using Editor.insertText(text, {undo: 'skip'}, a text insertion can be removed from the undo stack, and the same option can be provided for setTextInRange, which is what I was using previously.

Emacs Magit: how can I see differences between a given branch and unstaged changes?

With git I can see the differences in a file relative to any other past commit as:
git diff commit file_name
This shows me the differences in file_name between the version in commit against my current unstaged changes.
With Magit I can choose a given commit with . in the log and compare it with another commit with =. However I do not see my unstaged changes in the log so how can I select them to make the comparison?
Thank you in advance.
When in the main magit view (which you get after calling magit-status), you can press d to get a menu of all diff commands. Then press r (range) to diff against a specific commit (which is prompted in the minibuffer).
If you want the exact equivalent to your git command line and limit the diff to a specific file, then press =f before r (as always with magit, the "popup" is self-explanatory).
The complete sequence to get an equivalent of git diff commit file_name is thus :
d
=ffile_nameRET
rcommitRET

Accidental commit; how to not push an unpushed commit in Magit Emacs

I did an accidental commit which really makes no sense to have anywhere in history. How can I remove this commit from existence (especially I don't want it appear remotely).
In the magit-status, it shows:
Unpushed commits:
fe73b07 updated gitignore
974e70d test
ab333e6 trying to go with a flat structure
What can I do?
Bonus: actually, I just want to keep the "updated gitignore" from this commit.
Point at test, press E to start a rebase. M-n two swap commits. C-c C-c to finalize.
Resolve merge conflicts if any and done.
This is more a git question than an emacs or magit question really. If I understand you correctly, you want to get rid of older commits. One way to go about this is to re-order your commits and than get rid of the last two commits.
The first amounts to picking the right commits during rebase, the latter amounts to using the right incantation of git reset. I would suggest you take a look at this link on reordering commits. In addition, I would urge you to take a (ton of) look(s) at this useful fixup section of the step-by-step adventure through git.
Like #abo-abo said, initiate an interactive rebase by putting point on the first commit you want to remove and then pressing E (on Magit's next version ee.
A new log-like view appears, with every line prefixed with an action, initially pick. Then press n to move to the first commit you want to remove, and k, which will strike out that line meaning to drop that commit. (That's what happens in the ui, when this information is later feed to Git, the line is actually removed). This also moves to the next line, which in this case is the other commit you want to remove. So press k again.
Now that all commits you want to remove are marked as such, press C-c C-c to tell Git to make it happen.

Splitting a hunk with magit

I have 2 edits very close by (and therefore part of the same hunk), that I'd like to commit separately. Is it possible to split a hunk from within magit?
You can set the mark correctly with Ctrl+Space (C-SPC) and magit will only commit the selected portion.
You can also use - and + to decrease or increase the extent of the hunks in the diff (and 0 resets), but dominikh's answer is the most important one to know about.
Magit reuse diff-mode but don't expose many of diff-mode commands in its magit-revision-mode as this does VC package.
For example you can call diff-split-hunk which is usually C-c C-s in diff-mode.

emacs magit diff highlighting

I'm just getting started with magit.
I really like it, except that the diff viewer is really annoying to me. The chunk highlighting makes no sense because as I scroll around the cursor moves with the screen, highlighting new regions. There is also no other syntax highlighting in the magit diff mode. Does anybody know how to disable the chunk highlighting and get better diff colours other than white on gray?
Thanks.
This is an issue with Magit in combination with Emacs standard theme "wombat".
To work around this, do
M-x customize
Search for magit-item-highlight, click Show All Attributes, uncheck Inherit, then Save and Apply (or maybe only apply).
You lose the highlighting of the current hunk of the diff, but you can tell that still from the hunk's heading anyway, so it was somewhat redundant. Otherwise it resolves the issue nicely.
The zone highlighted correspond to the stash that would be staged when you hit "s".
Inside the hunk, the diff should be colored. You could test the development version (see https://github.com/magit/magit), and if this doesn't solve your issue, add comment in https://github.com/magit/magit/issues/133 about your configuration and exact problem.
There should be a customize group magit which allows you to customize all the different faces for the diff viewer.
In other words, you can run
M-x customize-group RET magit-faces RET
to see a list of all the faces used by Magit. The ones relevant to the diff viewer are, of course, the ones starting with Magit Diff.
Simply customize away and select Apply and Save. Alternatively, you can just use the Customize interface to see what faces are available, and then set them directly using set-face-foreground, set-face-background, and so on in your init-file.
If you're running the latest 1.0 version, you can also navigate to any of the diff chunks, hit the 'e' key to get an ediff presentation of the differences.
If you don't want to try M-x customize for some reason, simply place the following snippet in your init.el
(defun disable-magit-highlight-in-buffer ()
(face-remap-add-relative 'magit-item-highlight '()))
(add-hook 'magit-status-mode-hook 'disable-magit-highlight-in-buffer)
Source: https://github.com/magit/magit/issues/133