Skip to main content
Share Your Experience: Take the 2024 Developer Survey
130 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.8k
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
  • 18.3k
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,084
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,653
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

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.5k
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
  • 51.6k
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.8k
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
  • 51.6k
9 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,995
9 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
  • 51.6k
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
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
  • 51.6k
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
  • 51.6k
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
  • 30.6k
7 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
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,924
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.6k
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.8k
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
  • 51.6k
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.8k
6 votes
Accepted

Cannot get Magit to show the commit signatures in the log

The --show-signature argument can be selected in the log popup but it is not actually passed to git log. Instead %G? is added to the value of the --format= argument. That (%G?) causes some letter to ...
tarsius's user avatar
  • 25.8k
6 votes
Accepted

How to use `--no-edit` flag in a `git commit --amend` process inside magit?

That's exactly what c e (“extend”) does. And conversely, to change the commit message without amending the commit with the staged changes, there's c w (“reword”).
Gilles 'SO- stop being evil''s user avatar
5 votes
Accepted

Version control information out of sync with certain modes

When using diff-hl and magit => v2.4.0 you have to add this: (add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh) As far as the information in the mode-line is concerned, I would ...
tarsius's user avatar
  • 25.8k
5 votes

Magit git diff between two specific SHAs

If both commits are near each other in some Magit buffer, then it might be convenient to mark them using the region and then pressing d d. With such an active region "diff dwim" assumes that you want ...
tarsius's user avatar
  • 25.8k
5 votes

Magit how to use ssh key rather than being prompted for password

Edit ~/.ssh/config so that it contains the following: Host github.com IdentitiesOnly yes IdentityFile ~/.ssh/your_ssh_key Then whenever magit asks git to ask ssh to talk to github.com, ssh will ...
db48x's user avatar
  • 18.3k
5 votes
Accepted

Unable to use git in shell inside a buffer

M-x shell is a dumb terminal, whereas it looks like the commands you're using expect a more fully-featured terminal. This is what the "WARNING: terminal is not fully functional" messages are about. ...
phils's user avatar
  • 51.6k

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