Hot answers tagged

84

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, consult its documenation C-hfsmerge-modeRET to know them. Default prefix I find the default prefix for smerge-mode C-c^ cumbersome so I have changed it to C-...


66

With point over the desired commit, hit b b for checkout, and accept the default reference, which will look something like master~3.


64

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 "amend" the staged changes to the HEAD commit. Since commits are not mutable in Git, this will actually replace the old commit with a new commit. A buffer with ...


58

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 it. Press u again to set a new value. Starting with v2.4 and if the upstream is unset, you can also set upstream while pushing by using pu[REMOTE/]BRANCHRET. ...


54

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, and then pressing RET again.


45

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 TAB (also works for many other sections) to see the hunks. You can then stage an individual hunk, again by pressing s while point is inside it. You can even ...


33

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 items too Using either method will ask you to confirm before discarding.


31

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 alias to smerge-ediff). This will start the ediff interface. On the left will be the first merge parent, and the second merge parent on the right. They are ...


29

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 still only see directories which contain untracked files, not the files themselves. But these directory sections can now be expanded using TAB. One possible ...


28

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.


23

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 that tag] Move to the tag and press l o RET. That shows the log for that tag. Move to the commit and press RET. That shows information about that commit, ...


20

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

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 (--gpg-sign=) So type = S and the select a key. To avoid having to do that every time you create a commit you can save the value of that argument (and all other ...


16

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


15

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.


15

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 into the config file, so the other is ignored. (Actually, that's a lie but you can check the man page for details.) You can put quotes around a series of words ...


15

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 commands are described in the "Resetting" section of the manual: https://magit.vc/manual/magit/Resetting.html To reuse the commit message, you can use the =C option ...


14

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 changes can be discarded. When a staged change is discarded it is not only removed from the index (that is known as unstaging), but also from the work tree. To ...


12

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.org" # End: where someone@somwhere.org identify a gpg key you use for encrypting this file.


11

Specifically what I am after is to list the revision history at a certain tag It sounds like you already know the tag you need, in which case: Magit 1.x: lrl type tag name (with TAB completion) RETRET Magit 2.x: lo type tag name (with TAB completion) RET I have just completed a rebase and noticed some inconsistencies Or use the reflog to find the pre-...


11

No, Magit does not support that. Future versions might though. Git-Gutter does support it now. The command is named git-gutter:stage-hunk.


11

Press "P C-u C-u P" to make Magit ask you what remote and remote branch to use before pushing. (With a single prefix argument ("P C-u P") Magit asks what remote to use.) I found this by pressing P C-h k P in a Magit status buffer, reading the docs of magit-push and magit-push-dwim (these docs seem to be out of date, BTW), and experimenting. PS: I use ...


11

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 automatically reverted (changes are loaded). Check out the magit documentation for more info on how to use magit effectively.


11

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 in `magit-diff.el'. Whether to show word-granularity differences within diff hunks. nil never show fine differences. t show fine differences for the ...


10

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.


10

M-x vc-resolve-conflicts RET I bind it to C-xv<


10

In Magit this is available as magit-toplevel (but I agree with @abo-abo that it makes sense to use vc-root-dir).


10

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 requires somebody to rewrite shell scripts in C so that there is no more command forking. For me, its the interactive rebase that is the real killer (I can kick ...


10

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 there are of course situations when you want to do that - just don't call it a "merge". It would be much more appropriate to talk about "putting a file in the ...


9

Start with magit-status, then move to the file name under the "Untracked files" heading and hit s to stage it.


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