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, ...
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 "...
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.
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 ...
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,...
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 ...
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 ...
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 ...
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 ...
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.
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 (--...
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 ...
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 ...
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 ...
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
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.
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 ...
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
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.
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/...
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....
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 ...
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).
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:
...
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-...
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.
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 ...
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.
Community wiki
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"))
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
git × 239magit × 140
vc × 14
version-control × 13
mode-line × 9
org-mode × 8
dired × 7
microsoft-windows × 7
spacemacs × 6
ediff × 6
init-file × 5
helm × 5
projectile × 5
diff × 5
github × 5
emacsclient × 4
shell-command × 4
grep × 4
vc-mode × 4
osx × 3
tramp × 3
hooks × 3
ssh × 3
markdown-mode × 3
gpg × 3