Hot answers tagged

121 votes
Accepted

How to merge Git conflicts in Emacs

You might want to try out smerge-mode just open the conflicted file and do M-xsmerge-modeRET. It will highlight all the conflicted regions. It also adds keybindings to easily resolve the conflicts, ...
user avatar
  • 7,278
107 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 "...
user avatar
  • 24.2k
79 votes
Accepted

Can I checkout a given commit from magit's log view?

With point over the desired commit, hit b b for checkout, and accept the default reference, which will look something like master~3.
user avatar
  • 5,786
78 votes
Accepted

Change a branch's upstream with Magit

Starting with v2.1 you can change the upstream of the current branch to a remote or local branch using bu[REMOTE/]BRANCHRET. Starting with v2.4, if an upstream is already set, then bu will just unset ...
user avatar
  • 24.2k
77 votes
Accepted

How can I open a specific revision of a file with Magit?

You can view a file for a specific revision using M-x magit-find-file RET <filename> RET. Or you can first view the diff for commit by pressing RET on it, navigating to the file inside the diff,...
user avatar
  • 6,364
64 votes
Accepted

What's the Magit equivalent of 'git add'?

To stage a change press s with point on any "stageable change". This includes files listed below "Untracked files" and "Unstaged changes". You can also expand the files below "Unstaged files" using ...
user avatar
  • 24.2k
56 votes
Accepted

How can I discard changes to unstaged files using magit?

You can use one of the below to discard changes in unstaged files: M-x magit-revert-item (bound to v in magit-status-mode) M-x magit-discard-item (bound to k in magit-status-mode) - works on staged ...
user avatar
47 votes

How to merge Git conflicts in Emacs

Edit: since this answer got more upvotes than I expected, I expanded it a bit. To supplement the answer by @IqbalAnsari, you could also use vc-resolve-conflicts (as mentioned by others, it is an ...
user avatar
  • 1,436
37 votes
Accepted

Choose files to stage of a new directory with magit

Run: git config status.showUntrackedFiles all or if you want to enable this in all repositories: git config --global status.showUntrackedFiles all and refresh the status buffer. Initially you will ...
user avatar
  • 24.2k
36 votes

How can I open a specific revision of a file with Magit?

It's possible to do with plain VC (built-in to Emacs), without Magit. Type C-x v ~ and type the version you want. It understands tags and SHA1 hashes, as well as the usual ~1 etc suffixes.
user avatar
  • 5,786
31 votes
Accepted

How to automatically sign commits with magit?

In Magit commits are created using the committing popup (c). That popup would therefore be a good place to start looking for gpg support. If you do that, then you will find this: =S Sign using gpg (--...
user avatar
  • 24.2k
30 votes

How can I list available tags in Magit?

I would like to list the available tags in Magit ... Type y to show a buffer which lists branches, remote branches, and, at the bottom, tags. ...in order to diff a specific revision [reachable from ...
user avatar
  • 24.2k
29 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 ...
user avatar
  • 11.3k
25 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 ...
user avatar
  • 6,364
24 votes
Accepted

Untrack file without deleting it?

Hitting i will gitignore the file and untrack it from the git repository. Behind the scenes, it does git rm --cached - More info about this git command from a StackOverflow question
user avatar
  • 24.2k
20 votes

How to automatically sign commits with magit?

Try this in your $HOME/.gitconfig or your .git/config [user] email = YourEmail name = YourName signingkey = XXXXXXXX [commit] gpgsign = true Then just commit as usual.
user avatar
  • 985
19 votes

How can I discard changes to unstaged files using magit?

Reversing, reverting and discarding are distinct actions. Together with staging and unstaging, they are referred to as "apply variants". To discard a change means to throw it away. Only un-committed ...
user avatar
  • 24.2k
17 votes

How to start ediff-ing a file that has git conflict markers in it?

If you use magit, you can press e at the unmerged file in magit status buffer (started by pressing M-xmagit-statusRET) to start ediff session for resolving the conflicts
user avatar
  • 7,278
17 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.
user avatar
14 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/...
user avatar
  • 3,313
13 votes
Accepted

How to automatically encrypt orgmode files?

You just need to add ".gpg" at the end of the file name (for example, you could use "private.org.gpg" for an org file), and put at the end # Local Variables: # epa-file-encrypt-to: "someone@somwhere....
user avatar
  • 1,499
13 votes
Accepted

What is the best way to reload git stashed changes you've popped while file is open in buffer?

If you use magit you can create a stash with the z z command from the magit-status buffer. You can also pop a stash using the A command. If you use these commands, affected files will be ...
user avatar
  • 2,447
13 votes
Accepted

Get git repo root directory, preferably with magit

In Magit this is available as magit-toplevel (but I agree with @abo-abo that it makes sense to use vc-root-dir).
user avatar
  • 6,364
13 votes
Accepted

How do I set the upstream branch to push a local branch to in magit?

There are several ways to set the upstream, while pushing or without pushing at the same time. If magit-push-current-set-remote-if-missing is non-nil (the default), then you will see something like: ...
user avatar
  • 24.2k
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-...
user avatar
  • 11.3k
12 votes

How to start ediff-ing a file that has git conflict markers in it?

You can use the minor mode smerge-mode to move between conflicts and resolve them. You can open ediff to resolve conflicts with C-c ^ E while in smerge mode.
user avatar
12 votes
Accepted

How to well deal with the git diff with compatible to visual-line-mode?

You can customize/set magit-diff-refine-hunk to highlight word changes. magit-diff-toggle-refine-hunk, bound to D t, can be used to change it on the fly. magit-diff-refine-hunk is a variable defined ...
user avatar
  • 8,783
12 votes

What's the Magit equivalent of 'git add'?

Start with magit-status, then move to the file name under the "Untracked files" heading and hit s to stage it.
12 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"))
user avatar
  • 373
12 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 ...
user avatar
  • 1,690

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