Hot answers tagged


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-...


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 ...


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


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. ...


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.


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 ...


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.


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 ...


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 ...


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.


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. 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, ...


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 ...


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 ...


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: To reuse the commit message, you can use the =C option ...


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


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.


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 ...


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


In the Magit buffer, hit K (uppercase k) on the file. It works with magit 2.3; I don't know for earlier versions.


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.


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


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: Push feature to p pushRemote, after setting that u @{upstream}, after setting that e elsewhere To push to origin/feature and set that as upstream press u ...


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-header Each group of changes (called a "hunk") in the textual diff output is prefixed with a line of the form: @@ -k,l +n,m @@ TEXT ...


You just need to add ".gpg" at the end of the file name (for example, you could use "" for an org file), and put at the end # Local Variables: # epa-file-encrypt-to: "" # End: where identify a gpg key you use for encrypting this file.


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 ...


If you happen to use Spacemacs, I'd recommend activating "smerge-transient-mode", which brings up a hydra menu with all possible smerge commands. To do that, simply call M-x spacemacs/smerge-transient-state/body, which is per default assigned to SPC-g-r. Here's a screenshot: Editing your file should then be intuitive: Press n to go to the next hunk. ...


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: 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 ...


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-...


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


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 ...

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