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.
Related
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
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.
How to implement a functionality in emacs to show the difference of contents between two files opened in two buffers?
Kind of like revdiff when using mercurial.
Emacs has ediff, which can diff two files. To use it, just do M-x ediff, and specify the two files you want to diff.
BTW, if you want to see the differences between two blocks of text in the same buffer, you can do it as follows:
- make sure smerge-mode is loaded (e.g. M-x load-library RET smerge-mode RET).
- go to the beginning of the first bloc, C-SPC
- go the beginning of the second bloc, C-SPC
- go to the end of the second bloc, M-x smerge-makeup-conflict RET
- then you can use C-c ^ R or C-c ^ = to view the differences.
Note that this works better if the two blocs are pretty much consecutive.
M-x diff does that.
See the docs for more: http://www.gnu.org/software/emacs/manual/html_node/emacs/Comparing-Files.html
I also found that compare-windows does an amazing job cycling through differences in opened buffers.
I enjoy using magit and whenever I have to look at a diff outside of magit, it
occurs to me how inferior the default diff experience is.
Two aspects in particular:
1) refine diff automatically as I move into new hunks.
- diff-auto-refine-mode is not a substitute because I don't always move
with M-p and M-n.
2) white space differences are really obvious because
magit-whitespace-warning-face face is applied.
Is there a way to get these two features in diff-mode
I think sending a message to the Magit maintainers asking them to submit those changes for inclusion in diff-mode might do it.
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