Hot answers tagged

127 votes
Accepted

Add change to a previous commit with Magit

Let's pretend for a moment that you want to add something to the HEAD commit, i.e. "the second commit B" in your example. The commit popup on c features a binding "a Amend". Pressing that key will "...
tarsius's user avatar
  • 25.7k
37 votes
Accepted

How can I use emacs with git within the terminal?

When you run git config --global core.editor emacs -nw, your shell splits the command line into words before invoking git. Git thus sees "emacs -nw" as two separate arguments. It only needs one to put ...
db48x's user avatar
  • 17.9k
28 votes
Accepted

Magit - Undo last commit - History Manipulation

You can use magit-reset (bound by default to x). The commit at point will be used as the default for the prompt, but you can enter any revision value you'd like ("HEAD~" here). The resetting ...
Kyle Meyer's user avatar
  • 7,024
23 votes

Untrack file without deleting it?

In the Magit buffer, hit K (uppercase k) on the file. It works with magit 2.3; I don't know for earlier versions.
Patrick Fournier's user avatar
18 votes
Accepted

DOOM Emacs: Error running hook "global-git-commit-mode" because: (void-variable transient-base-map)

It seems that some magit dependencies break with Emacs 28, as the function defvar-keymap is only added in Emacs 29. The solution is to pin an older version of the packages, as Doom currently does not ...
Eric's user avatar
  • 306
15 votes

How to merge Git conflicts in Emacs

If you happen to use Spacemacs, I'd recommend activating "smerge-transient-state", which brings up a hydra menu with all possible smerge commands. To do that, simply call M-x spacemacs/...
Daniel's user avatar
  • 3,643
13 votes

How to change options passed to git vc-annotate?

With Emacs 25.1 you can pass options to git blame using the vc-git-annotate-switches variable: (setq vc-git-annotate-switches '("-w"))
skybert's user avatar
  • 383
13 votes
Accepted

Magit extremely slow in Windows. How do I optimize?

I have actually done rather a lot of research on this and fundamentally the problem is that git for windows sucks This is the upstream bug: https://github.com/git-for-windows/git/issues/596 and it ...
fommil's user avatar
  • 1,780
13 votes
Accepted

How can I make 'git diff' aware of Emacs Lisp functions?

Is it possible to make Git aware of how to identify a useful line to use for the @@ line? Yes, quoth section "Defining a custom hunk-header" in man 5 gitattributes: Defining a custom hunk-...
Basil's user avatar
  • 12.3k
12 votes
Accepted

How can I do a git diff on the current file with magit?

Firstly, make sure you're aware of https://stackoverflow.com/a/17799517 If you want a Magit diff buffer for the current file, you can call magit-diff-buffer-file directly, or use the "diff" option (d) ...
phils's user avatar
  • 50.8k
12 votes
Accepted

How do I visit a file on a different branch?

So I was confused because the options to choose from for C-x v ~ only showed older revisions of the file on this particular branch, but you can in fact specify a branch and have that file shown. Ie. ...
alecvn's user avatar
  • 419
10 votes
Accepted

Merge specific files with magit

As noted in many answers to the question you have linked to and even more so in comments on those answers, git checkout source_branch -- <paths>... does not perform a merge. Never-the-less ...
tarsius's user avatar
  • 25.7k
10 votes
Accepted

Magit remove local branches that were merged into another branch

The refs buffer has options to filter to merged branches. Quoting C-hig (magit)References Buffer: ‘y’ (‘magit-show-refs’) This command lists branches and tags in a dedicated buffer. However if this ...
phils's user avatar
  • 50.8k
9 votes
Accepted

Magit how to cancel running git process

You can use M-x magit-process-kill in the Magit process buffer ($, or M-x magit-process-buffer jumps to process buffer for the current repository). magit-process-kill is an interactive Lisp closure ...
npostavs's user avatar
  • 9,193
8 votes
Accepted

Function of org-clock-save.el file and Git related question

The file org-save-clock.el is used to store two kinds of information: the active clock if emacs is shut down while a task is active (gets stored in org-clock-stored-resume-clock) the history of the n ...
dfeich's user avatar
  • 1,904
8 votes

magit-stash-create: Cannot save the current index state

This could also be due to not having configured git properly: git config --global user.email "[email protected]" git config --global user.name "Your Name"
Clément's user avatar
  • 3,973
8 votes
Accepted

Magit - How do I sync my feature branch with the latest master without checking out master?

There's no need to checkout a local copy of master. You just need to fetch the current ref for the remote origin/master branch (assuming the appropriate remote is named origin), and then use that. ...
phils's user avatar
  • 50.8k
8 votes
Accepted

How to install latest version of org mode?

[As requested, expanding the comment into an answer] The main idea is that you need to make sure that Org mode is set up, using the new bits that you downloaded only. Emacs comes with a version of ...
NickD's user avatar
  • 29.6k
8 votes
Accepted

How to properly use Magit Fixup?

f just creates the fixup! commit. You wanted the upper-case F -- that ("Instant Fixup") is the variant which automatically performs the rebase after creating the fixup! commit. You can ...
phils's user avatar
  • 50.8k
7 votes
Accepted

Indicate whether file has uncommited changes in mode line

Well, vc does that by default. From its documentation (emphasis mine): When you visit a file that is under version control, Emacs indicates this on the mode line. For example, ‘Bzr-1223’ says ...
JeanPierre's user avatar
  • 7,423
7 votes

Magit: how remove push branch?

Bring up the magit status window with M-x magit-status or whatever shortcut key binding you use. type b to bring up the branch menu. type p to cycle through the push options enough times to get to ...
icarus's user avatar
  • 1,914
7 votes

Show a list of names for all git projects

One existing approach is: https://magit.vc/manual/magit/Repository-List.html#Repository-List. After setting magit-repository-directories, you can use M-x magit-list-repositories to display these ...
xuchunyang's user avatar
  • 14.5k
7 votes
Accepted

What is the equivalent of doing a plain `git reset <sha>` in magit?

Use x or X s to do so. Using the X prefix has the benefit that it shows you all the available git reset variants. This is also documented in the Resetting section of the manual.
tarsius's user avatar
  • 25.7k
6 votes

Set author per repository

you can do this with one-time git configuration. you can use it for email and so on, but also for using a different ssh key: in ~/.gitconfig: [includeIf "gitdir:~/work/"] path = .gitconfig_work in ~...
wouter bolsterlee's user avatar
6 votes

Set author per repository

One way to do this is to set the author configuration in .git/config in each repository, in the same format as in ~/.gitconfig, i.e.: [user] name = My Name email = [email protected]
legoscia's user avatar
  • 6,052
6 votes

Enable smerge-mode for already opened file

This is what I have in my init file : (defun smerge-try-smerge () (save-excursion (goto-char (point-min)) (when (re-search-forward "^<<<<<<< " nil t) (require '...
YoungFrog's user avatar
  • 3,526
6 votes

How do I make Magit only show diff for unstaged changes?

Try M-x magit-diff-unstaged, also available in the diff popup (d u). If you've globally bound magit-dispatch-popup to some key,then you can use that followed by d u to get to the unstaged diffs ...
glucas's user avatar
  • 20.6k
6 votes
Accepted

How do you do "git checkout -- .emacs" using magit?

Either stash the modifications with z or kill the modifications with k. The latter, with point at .emacs, is the equivalent of checking out the latest/unmodified revision of that file. You can also ...
phils's user avatar
  • 50.8k
6 votes
Accepted

Magit git diff between two specific SHAs

Use the diff range command with the .. syntax: dr SHA#1..SHA#2 Refer to the git diff man page: git diff [--options] <commit> <commit> [--] [<path>...] This is to view ...
phils's user avatar
  • 50.8k
6 votes

How to ask magit to use external diff and merge tools?

Magit does not support invoking external diff tools and it will be a very long time until I get around to implementing such support because I am focused on improving the internal tools instead so that ...
tarsius's user avatar
  • 25.7k

Only top scored, non community-wiki answers of a minimum length are eligible