forked from magit/magit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
magit.texi
1475 lines (1167 loc) · 61.5 KB
/
magit.texi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\input texinfo.tex @c -*-texinfo-*-
@c %**start of header
@setfilename magit.info
@settitle Magit User Manual
@documentencoding utf-8
@c %**end of header
@macro magit{url, text}
@uref{https://github.com/magit/magit/\url\, \text\}
@end macro
@dircategory Emacs
@direntry
* Magit: (magit). Using Git from Emacs with Magit.
@end direntry
@copying
Copyright @copyright{} 2008-2013 Magit contributors. (See the header
of magit.el for the lengthy list of Magit contributors.)
@quotation
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the section entitled
``GNU Free Documentation License''.
@end quotation
@end copying
@node Top
@top Magit User Manual
Magit is an interface to the version control system Git, implemented
as an Emacs extension.
Unlike Emacs's native Version Control package which strives to
provide a unified interface to various version control systems, Magit
only supports Git and can therefor better take advantage of its native
features.
Magit supports GNU Emacs 23.2 or later; 24.1 or later is recommended.
Magit supports Git 1.7.2.5 or later; 1.8.2 or later is recommended.
The minimal versions are those available in Debian oldstable.
When something breaks please see the curated list of
@magit{wiki/Known-Issues, known issues} and the @magit{wiki/FAQ, FAQ}.
If that doesn't help check the list of all open issues @magit{issues,
issues}.
If everything else fails please open a new issue or ask for help on
the @uref{https://groups.google.com/forum/?fromgroups#!forum/magit,
mailing list}.
@menu
* Introduction::
* Acknowledgments::
* Sections::
* Status::
* Untracked files::
* Staging and Committing::
* History::
* Reflogs::
* Commit Buffer::
* Diffing::
* Tagging::
* Resetting::
* Stashing::
* Branches and Remotes::
* Wazzup::
* Merging::
* Rebasing::
* Interactive Rebasing::
* Rewriting::
* Pushing and Pulling::
* Submodules::
* Bisecting::
* Finding commits not merged upstream::
* Using Magit Extensions::
* Using Git Directly::
* GNU Free Documentation License::
@end menu
@node Introduction
@chapter Introduction
With Magit, you can inspect and modify your Git repositories with
Emacs. You can review and commit the changes you have made to the
tracked files, for example, and you can browse the history of past
changes. There is support for cherry picking, reverting, merging,
rebasing, and other common Git operations.
Magit is not a complete interface to Git; it just aims to make the
most common Git operations convenient. Thus, Magit will likely not
save you from learning Git itself.
This manual provides a tour of many Magit features. It isn't an
introduction to version control in general, or to Git in particular.
The main entry point to Magit is @kbd{M-x magit-status}, which puts
you in Magit's status buffer. You will be using it frequently, so it
is probably a good idea to globally bind @code{magit-status} to a key
of your choice.
In addition to the status buffer, Magit will also create buffers that
show lists of commits, buffers with diffs, and other kinds of buffers.
All these buffers are in a mode derived from @code{magit-mode} and
have the similar key bindings. Not all commands make sense in all
contexts, but a given key will do the same thing in different Magit
buffers.
Naturally, Magit runs the @code{git} command to do most of the work.
The @code{*magit-process*} buffer contains the transcript of the most
recent command. You can switch to it with @kbd{$}.
@node Acknowledgments
@chapter Acknowledgments
Our thank goes to all current and past contributors, Marius Vollmer
who started the project, and all retired and current maintainers,
Phil Jackson, Peter J. Weisberg, Rémi Vanicat, Nicolas Dudebout,
Yann Hodique, and Jonas Bernoulli.
For a full list of contributors, see the AUTHORS.md file at the
top-level directory of this distribution or at
@magit{tree/master/AUTHORS.md}.
@node Sections
@chapter Sections
All Magit buffers are structured into nested 'sections'. These
sections can be hidden and shown individually. When a section is
hidden, only its first line is shown and all its children are
completely invisible.
The most fine-grained way to control the visibility of sections is the
@kbd{TAB} key. It will to toggle the current section (the section
that contains point) between being hidden and being shown.
Typing @kbd{S-TAB} toggles the visibility of the children of the
current section. When all of them are shown, they will all be hidden.
Otherwise, when some or all are hidden, they will all be shown.
The digit keys @kbd{1}, @kbd{2}, @kbd{3}, and @kbd{4} control the
visibility of sections based on levels. Hitting @kbd{2}, for example,
will show sections on levels one and two, and will hide sections on
level 3. However, only sections that are a parent or child of the
current section are affected.
For example, when the current section is on level 3 and you hit
@kbd{1}, the grand-parent of the current section (which is on level
one) will be shown, and the parent of the current section (level 2)
will be hidden. The visibility of no other section will be changed.
This sounds a bit complicated, but you'll figure it out.
Using @kbd{M-1}, @kbd{M-2}, @kbd{M-3}, and @kbd{M-4} is similar to the
unmodified digits, but now all sections on the respective level are
affected, regardless of whether or not they are related to the current
section.
For example, @kbd{M-1} will only show the first lines of the top-level
sections and will hide everything else. Typing @kbd{M-4} on the other
hand will show everything.
Because of the way the status buffer is set up, some changes to
section visibility are more common than others. Files are on level 2
and diff hunks are on level 4. Thus, you can type @kbd{2} to collapse
the diff of the current file, and @kbd{M-2} to collapse all files.
This returns the status buffer to its default setup and is a quick way
to unclutter it after drilling down into the modified files.
Because @kbd{2} and @kbd{M-2} are so common in the status buffer, they
are bound to additional, more mnemonic keys: @kbd{M-h} (hide) and
@kbd{M-H} (hide all). Likewise @kbd{4} and @kbd{M-4} are also
available as @kbd{M-s} (show) and @kbd{M-S} (show all).
In other buffers than the status buffer, @kbd{M-h}, @kbd{M-H},
@kbd{M-s}, and @kbd{M-S} might work on different levels than on 2 and
4, but they keep their general meaning: @kbd{M-H} hides all detail,
and @kbd{M-S} shows everything.
@node Status
@chapter Status
Running @kbd{M-x magit-status} displays the main interface of Magit,
the status buffer. You can have multiple status buffers active at the
same time, each associated with its own Git repository.
When invoking @kbd{M-x magit-status} from within a Git repository, it
will switch to the status buffer of that repository. Otherwise, it
will prompt for a directory. With a prefix argument, it will always
prompt.
You can set @code{magit-repo-dirs} to customize how
@code{magit-status} asks for the repository to work on. When
@code{magit-repo-dirs} is nil, @code{magit-status} will simply ask for
a directory.
If you specify a directory that is not a Git repository, @kbd{M-x
magit-status} will offer to initialize it as one.
When @code{magit-repo-dirs} is not nil, it is treated as a list of
directory names, and @code{magit-status} will find all Git
repositories in those directories and offer them for completion.
(Magit will only look @code{magit-repo-dirs-depth} levels deep,
however.)
With two prefix arguments, @code{magit-status} will always prompt for
a raw directory.
Thus, you would normally set @code{magit-repo-dirs} to the places
where you keep most of your Git repositories and switch between them
with @kbd{C-u M-x magit-status}. If you want to go to a repository
outside of your normal working areas, or if you want to create a new
repository, you would use @kbd{C-u C-u M-x magit-status}.
You need to explicitly refresh the status buffer when you have made
changes to the repository from outside of Emacs. You can type @kbd{g}
in the status buffer itself, or just use @kbd{M-x magit-status}
instead of @kbd{C-x b} when switching to it. You also need to refresh
the status buffer in this way after saving a file in Emacs.
The header at the top of the status buffer shows a short summary of
the repository state: where it is located, which branch is checked
out, etc. Below the header are a number of sections that show details
about the working tree and the staging area. You can hide and show
them as described in the previous section.
The first section shows @emph{Untracked files}, if there are any. See
@ref{Untracked files} for more details.
The next two sections show your local changes. They are explained
fully in the next chapter, @ref{Staging and Committing}.
If the current branch is associated with a remote tracking branch, the
status buffer shows the differences between the current branch and the
tracking branch. See @ref{Pushing and Pulling} for more information.
During a history rewriting session, the status buffer shows the
@emph{Pending changes} and @emph{Pending commits} sections. See
@ref{Rewriting} for more details.
@node Untracked files
@chapter Untracked files
Untracked files are shown in the @emph{Untracked files} section.
You can add an untracked file to the staging area with @kbd{s}. If
point is on the @emph{Untracked files} section title when you hit
@kbd{s}, all untracked files are staged.
Typing @kbd{C-u S} anywhere will also stage all untracked files,
together with all changes to the tracked files.
You can instruct Git to ignore them by typing @kbd{i}. This will add
the filename to the @code{.gitignore} file. Typing @kbd{C-u i} will ask
you for the name of the file to ignore. This is useful to ignore whole
directories, for example. In this case, the minibuffer's future history
(accessible with @kbd{M-n}) contains predefined values (such as
wildcards) that might be of interest. If prefix argument is negative
(for example after typing @kbd{C-- i}), the prompt proposes wildcard by
default. The @kbd{I} command is similar to @kbd{i} but will add the
file to @code{.git/info/exclude} instead.
To delete an untracked file forever, use @kbd{k}. If point is on the
@emph{Untracked files} section title when you hit @kbd{k}, all
untracked files are deleted.
@node Staging and Committing
@chapter Staging and Committing
Committing with Git is a two step process: first you add the changes
you want to commit to a 'staging area' or 'index', and then you commit
them to the repository. This allows you to only commit a subset of
the changes in the working tree. If you are not familiar with this
concept yet, then you should change that as soon as possible using one
of the fine Git tutorials. If you don't, then Git and by extension
Magit will seem rather strange.
Magit shows uncommitted changes in two sections, depending on whether
the changes have been staged yet. The @emph{Staged changes} section
shows the changes that will be included in the next commit, while the
@emph{Unstaged changes} section shows the changes that will be left
out.
To move an unstaged hunk into the staging area, move point into the
hunk and type @kbd{s}. Likewise, to unstage a hunk, move point into
it and type @kbd{u}. If point is in a diff header when you type
@kbd{s} or @kbd{u}, all hunks belonging to that diff are moved at the
same time.
Currently it is only possible to stage from the status buffer.
Staging and unstaging from diff buffers that show unstaged and staged
changes is not possible yet.
If the region is active when you type @kbd{s} or @kbd{u}, only the
changes in the region are staged or unstaged. (This works line by
line: if the beginning of a line is in the region it is included in
the changes, otherwise it is not.)
To change the size of the hunks, you can type @kbd{+} or @kbd{-} to
increase and decrease, respectively. Typing @kbd{0} will
reset the hunk size to the default.
Typing @kbd{C-u s} will ask you for a name of a file to be staged, for
example to stage files that are hidden.
To move all hunks of all diffs into the staging area in one go, type
@kbd{S}. To unstage everything, type @kbd{U}.
Typing @kbd{C-u S} will stage all untracked files in addition to the
changes to tracked files.
You can discard uncommitted changes by moving point into a hunk and
typing @kbd{k}. The changes to discard are selected as with @kbd{s}
and @kbd{u}.
Before committing, you should write a short description of the
changes.
Type @kbd{c c} to pop up a buffer where you can write your change
description. Once you are happy with the description, type @kbd{C-c
C-c} in that buffer to perform the commit.
If you want to write changes in a @file{ChangeLog} file, you can use
@kbd{C-x 4 a} on a diff hunk.
Typing @kbd{c c} when the staging area is unused is a special
situation. Normally, the next commit would be empty, but you can
configure Magit to do something more useful by customizing the
@code{magit-commit-all-when-nothing-staged} variable. One choice is
to instruct the subsequent @kbd{C-c C-c} to commit all changes.
Another choice is stage everything at the time of hitting @kbd{c c}.
Typing @kbd{M-n} or @kbd{M-p} will cycle through the
@code{log-edit-comment-ring}, which will have your previous log
messages. This is particularly useful if you have a hook that
occasionally causes git to refuse your commit.
To abort a commit use @kbd{C-c C-k}. The commit message is saved and
can later be retrieved in the commit message buffer using @kbd{M-n}
and @kbd{M-p}.
Typing @kbd{C} will also pop up the change description buffer, but in
addition, it will try to insert a ChangeLog-style entry for the change
that point is in.
@node History
@chapter History
To show the repository history of your current head, type @kbd{l l}. A
new buffer will be shown that displays the history in a terse form.
The first paragraph of each commit message is displayed, next to a
representation of the relationships between commits.
To show the repository history between two branches or between any two
points of the history, type @kbd{l r l}. You will be prompted to enter
references for starting point and ending point of the history range; you
can use auto-completion to specify them. A typical use case for ranged
history log display would be @kbd{l r l master RET new-feature RET} that
will display commits on the new-feature branch that are not in master;
these commits can then be inspected and cherry-picked, for example.
More thorough filtering can be done by supplying @kbd{l} with one or
more suffix arguments, as displayed in its popup. @kbd{=g} ('Grep')
for example, limits the output to commits of which the log message
matches a specific string/regex.
Typing @kbd{l L} (or @kbd{l C-u L}) will show the log in a more verbose
form.
Magit will show only @code{magit-log-cutoff-length} entries. @kbd{e}
will show twice as many entries. @kbd{C-u e} will show all entries,
and given a numeric prefix argument, @kbd{e} will add this number of
entries.
You can move point to a commit and then cause various things to happen
with it. (The following commands work in any list of commits, such as
the one shown in the @emph{Unpushed commits} section.)
Typing @kbd{RET} will pop up more information about the current commit
and move point into the new buffer. @xref{Commit Buffer}. Typing
@kbd{SPC} and @kbd{DEL} will also show the information, but will
scroll the new buffer up or down (respectively) when typed again.
Typing @kbd{a} will apply the current commit to your current branch.
This is useful when you are browsing the history of some other branch
and you want to `cherry-pick' some changes from it. A typical
situation is applying selected bug fixes from the development version
of a program to a release branch. The cherry-picked changes will not
be committed automatically; you need to do that explicitly.
Typing @kbd{A} will cherry-pick the current commit and will also
commit the changes automatically when there have not been any
conflicts.
Typing @kbd{v} will revert the current commit. Thus, it will apply
the changes made by that commit in reverse. This is obviously useful
to cleanly undo changes that turned out to be wrong. As with @kbd{a},
you need to commit the changes explicitly.
Typing @kbd{C-w} will copy the sha1 of the current commit into the
kill ring.
Typing @kbd{=} will show the differences from the current commit to
the @dfn{marked} commit.
You can mark the current commit by typing @kbd{.}. When the current
commit is already marked, typing @kbd{.} will unmark it. To unmark
the marked commit no matter where point is, use @kbd{C-u .}.
Some commands, such as @kbd{=}, will use the current commit and the
marked commit as implicit arguments. Other commands will offer the
marked commit as a default when prompting for their arguments.
@node Reflogs
@chapter Reflogs
You can use @kbd{l h} and @kbd{l H} to browse your @emph{reflog}, the
local history of changes made to your repository heads. Typing
@kbd{H} will ask for a head, while @kbd{l h} will show the reflog of
@code{HEAD}.
The resulting buffer is just like the buffer produced by @kbd{l l} and
@kbd{l L} that shows the commit history.
@node Commit Buffer
@chapter Commit Buffer
When you view a commit (perhaps by selecting it in the log buffer,
@ref{History}), the ``commit buffer'' is displayed, showing you
information about the commit and letting you interact with it.
By placing your cursor within the diff or hunk and typing @kbd{a}, you
can apply the same patch to your working copy. This is useful when
you want to copy a change from another branch, but don't necessarily
want to cherry-pick the whole commit.
By typing @kbd{v} you can apply the patch in reverse, removing all the
lines that were added and adding all the lines that were removed.
This is a convenient way to remove a change after determining that it
introduced a bug.
If the commit message refers to any other commits in the repository by
their unique hash, the hash will be highlighted and you will be able
to visit the referenced commit either by clicking on it or by moving
your cursor onto it and pressing @kbd{RET}.
The commit buffer maintains a history of the commits it has shown.
After visiting a referenced commit you can type @kbd{C-c C-b} to get
back to where you came from. To go forward in the history, type
@kbd{C-c C-f}. There are also @code{[back]} and @code{[forward]}
buttons at the bottom of the buffer.
@node Diffing
@chapter Diffing
Magit typically shows diffs in the ``unified'' format.
In any buffer that shows a diff, you can type @kbd{e} anywhere within
the diff to show the two versions of the file in Ediff. If the diff
is of a file in the status buffer that needs to be merged, you will be
able to use Ediff as an interactive merge tool. Otherwise, Ediff will
simply show the two versions of the file.
To show the changes from your working tree to another revision, type
@kbd{d}. To show the changes between two arbitrary revisions, type
@kbd{D}.
You can use @kbd{a} within the diff output to apply the changes to
your working tree. As usual when point is in a diff header for a
file, all changes for that file are applied, and when it is in a hunk,
only that hunk is. When the region is active, the applied changes are
restricted to that region.
Typing @kbd{v} will apply the selected changes in reverse.
@node Tagging
@chapter Tagging
Typing @kbd{t t} will make a lightweight tag. Typing @kbd{t - a t} will
make an annotated tag. It will put you in the normal
@code{*magit-log-edit} buffer for writing commit messages, but typing
@kbd{C-c C-c} in it will make the tag instead. This is controlled by
the @code{Tag} field that will be added to the @code{*magit-log-edit*}
buffer. You can edit it, if you like.
@node Resetting
@chapter Resetting
Once you have added a commit to your local repository, you can not
change that commit anymore in any way. But you can reset your current
head to an earlier commit and start over.
If you have published your history already, rewriting it in this way
can be confusing and should be avoided. However, rewriting your local
history is fine and it is often cleaner to fix mistakes this way than
by reverting commits (with @kbd{v}, for example).
Typing @kbd{x} will ask for a revision and reset your current head to
it. No changes will be made to your working tree and staging area.
Thus, the @emph{Staged changes} section in the status buffer will show
the changes that you have removed from your commit history. You can
commit the changes again as if you had just made them, thus rewriting
history.
Typing @kbd{x} while point is in a line that describes a commit will
offer this commit as the default revision to reset to. Thus, you can
move point to one of the commits in the @emph{Unpushed commits}
section and hit @kbd{x RET} to reset your current head to it.
Type @kbd{X} to reset your working tree and staging area to the most
recently committed state. This will discard your local modifications,
so be careful.
You can give a prefix to @kbd{x} if you want to reset both the current
head and your working tree to a given commit. This is the same as
first using an unprefixed @kbd{x} to reset only the head, and then
using @kbd{X}.
@node Stashing
@chapter Stashing
You can create a new stash with @kbd{z z}. Your stashes will be listed
in the status buffer, and you can apply them with @kbd{a} and pop them
with @kbd{A}. To drop a stash, use @kbd{k}.
With a prefix argument, both @kbd{a} and @kbd{A} will attempt to
reinstate the index as well as the working tree from the stash.
Typing @kbd{z -k z} will create a stash just like @kbd{z z}, but will
leave the changes in your working tree and index. This makes it easier
to, for example, test multiple variations of the same change.
If you just want to make quick snapshots in between edits, you can use
@kbd{z s}, which automatically enters a timestamp as description, and
keeps your working tree and index intact by default.
You can visit and show stashes in the usual way: Typing @kbd{SPC} and
@kbd{DEL} will pop up a buffer with the description of the stash and
scroll it, typing @kbd{RET} will move point into that buffer. Using
@kbd{C-u RET} will move point into that buffer in other window.
@node Branches and Remotes
@chapter Branches and Remotes
The current branch is indicated in the header of the status buffer. If
this branch is tracking a remote branch, the latter is also indicated.
Branches and remotes can be manipulated directly with a popup menu or
through the branch manager. Using the popup menu allows you to quickly
make changes from any magit buffer. The branch manager is a separate
buffer called @code{*magit-branches*}. It displays information about
branches and remotes and offers a local key map for shorter key
bindings. The two interaction methods are described in more details
below.
@menu
* Branches Popup::
* Remotes Popup::
* Branches in the Branch Manager::
* Remotes in the Branch Manager::
@end menu
@node Branches Popup
@section Branches Popup
Typing @kbd{b} will display a popup menu to manipulate branches.
You can switch to a different branch by typing @kbd{b b}. This will
immediately checkout the branch into your working copy, so you
shouldn't have any local modifications when switching branches.
If you try to switch to a remote branch, Magit will offer to create a
local tracking branch for it instead. This way, you can easily start
working on new branches that have appeared in a remote repository.
Typing @kbd{b b} while point is at a commit description will offer
that commit as the default to switch to. This will result in a
detached head.
To create a new branch and switch to it immediately, type @kbd{b c}.
To delete a branch, type @kbd{b k}. If you're currently on that
branch, Magit will offer to switch to the 'master' branch.
Typing @kbd{b r} will let you rename a branch. Unless a branch with the same
name already exists, obviously...
Deleting a branch is only possible if it's already fully merged into
HEAD or its upstream branch. Unless you type @kbd{b C-u k}, that is.
Here be dragons...
Typing @kbd{b v} will launch the branch manager.
@node Remotes Popup
@section Remotes Popup
Typing @kbd{M} will display a popup menu to manipulate remotes.
To add a new remote, type @kbd{M a}.
To delete a remote type @kbd{M k}.
Typing @kbd{M r} will let you rename a remote.
@node Branches in the Branch Manager
@section Branches in the Branch Manager
In the branch manager, each branch is displayed on a separate line. The
current local branch is marked by a ``*'' in front of the name. Remote
branches are grouped by the remote they come from.
If a local branch tracks a remote branch some extra information is
printed on the branch line. The format is the following: ``<branch>
[<remote-branch> @ <remote>: ahead <a>, behind <b>]''.
``<remote-branch>'' is omitted if it is identical to ``<branch>''.
``ahead'' and ``behind'' information are only displayed if necessary.
To check out a branch, move your cursor to the desired branch and
press @kbd{RET}.
Typing @kbd{c} will create a new branch.
Typing @kbd{k} will delete the branch in the current line, and
@kbd{C-u k} deletes it even if it hasn't been merged into the current
local branch. Deleting works for both local and remote branches.
Typing @kbd{r} on a branch will rename it.
Typing @kbd{T} on a local branch, changes which remote branch it
tracks.
@node Remotes in the Branch Manager
@section Remotes in the Branch Manager
In the branch manager, each remote is displayed on a separate line. The
format is the following ``<remote> (<url>, <push-url>)''. ``<push-url>''
is omitted if it is not set. The associated branches are listed under
this line.
Typing @kbd{a} will add a new remote.
Typing @kbd{k} will delete the remote in the current line.
Typing @kbd{r} on a remote will rename it.
@node Wazzup
@chapter Wazzup
Typing @kbd{w} will show a summary of how your other branches relate
to the current branch.
For each branch, you will get a section that lists the commits in that
branch that are not in the current branch. The sections are initially
collapsed; you need to explicitly open them with @kbd{TAB} (or
similar) to show the lists of commits.
When point is on a @emph{N unmerged commits in ...} title, the
corresponding branch will be offered as the default for a merge.
Hitting @kbd{i} on a branch title will ignore this branch in the
wazzup view. You can use @kbd{C-u w} to show all branches, including
the ignored ones. Hitting @kbd{i} on an already ignored branch in
that view will unignore it.
@node Merging
@chapter Merging
Magit offers two ways to merge branches: manual and automatic. A
manual merge will apply all changes to your working tree and staging
area, but will not commit them, while an automatic merge will go ahead
and commit them immediately.
Type @kbd{m m} to initiate merge.
After initiating a merge, the header of the status buffer might remind
you that the next commit will be a merge commit (with more than one
parent). If you want to abort a manual merge, just do a hard reset to
HEAD with @kbd{X}.
Merges can fail if the two branches you want to merge introduce
conflicting changes. In that case, the automatic merge stops before the
commit, essentially falling back to a manual merge. You need to resolve
the conflicts for example with @kbd{e} and stage the resolved files, for
example with @kbd{S}.
You can not stage individual hunks one by one as you resolve them, you
can only stage whole files once all conflicts in them have been
resolved.
@node Rebasing
@chapter Rebasing
Typing @kbd{R} in the status buffer will initiate a rebase or, if one
is already in progress, ask you how to continue.
When a rebase is stopped in the middle because of a conflict, the
header of the status buffer will indicate how far along you are in the
series of commits that are being replayed. When that happens, you
should resolve the conflicts and stage everything and hit @kbd{R c} to
continue the rebase. Alternatively, hitting @kbd{c} or @kbd{C} while
in the middle of a rebase will also ask you whether to continue the
rebase.
Of course, you can initiate a rebase in any number of ways, by
configuring @code{git pull} to rebase instead of merge, for example.
Such a rebase can be finished with @kbd{R} as well.
@node Interactive Rebasing
@chapter Interactive Rebasing
Typing @kbd{E} in the status buffer will initiate an interactive
rebase. This is equivalent to running @code{git rebase --interactive}
at the command line. The @file{git-rebase-todo} file will be opened in
an Emacs buffer for you to edit. This file is opened using
@code{emacsclient}, so just edit this file as you normally would, then
call the @code{server-edit} function (typically bound to @kbd{C-x #})
to tell Emacs you are finished editing, and the rebase will proceed as
usual.
If you have loaded @file{rebase-mode.el} (which is included in the
Magit distribution), the @file{git-rebase-todo} buffer will be in
@code{rebase-mode}. This mode disables normal text editing but instead
provides single-key commands (shown in the buffer) to perform all the
edits that you would normally do manually, including changing the
operation to be performed each commit (``pick'', ``squash'', etc.),
deleting (commenting out) commits from the list, and reordering
commits. You can finish editing the buffer and proceed with the rebase
by pressing @kbd{C-c C-c}, which is bound to @code{server-edit} in
this mode, and you can abort the rebase with @kbd{C-c C-k}, just like
when editing a commit message in Magit.
@node Rewriting
@chapter Rewriting
As hinted at earlier, you can rewrite your commit history. For
example, you can reset the current head to an earlier commit with
@kbd{x}. This leaves the working tree unchanged, and the status
buffer will show all the changes that have been made since that new
value of the current head. You can commit these changes again,
possibly splitting them into multiple commits as you go along.
Amending your last commit is a common special case of rewriting
history like this.
Another common way to rewrite history is to reset the head to an
earlier commit, and then to cherry pick the previous commits in a
different order. You could pick them from the reflog, for example.
Magit has several commands that can simplify the book keeping
associated with rewriting. These commands all start with the @kbd{r}
prefix key.
(Unless you already do so, we recommend that you don't use the
functionality described here. It is semi-deprecated and will be
removed once its unique features have been ported to the @code{git
rebase --interactive} workflow. Even now the latter is almost always
the better option.)
Typing @kbd{r b} will start a rewrite operation. You will be prompted
for a @emph{base} commit. This commit and all subsequent commits up
until the current head are then put in a list of @emph{Pending
commits}, after which the current head will be reset to the
@emph{parent} of the base commit. This can be configured to behave
like @code{git rebase}, i.e. exclude the selected base commit from the
rewrite operation, with the @code{magit-rewrite-inclusive} variable.
You would then typically use @kbd{a} and @kbd{A} to cherry pick
commits from the list of pending commits in the desired order, until
all have been applied. Magit shows which commits have been applied by
changing their marker from @code{*} to @code{.}.
Using @kbd{A} will immediately commit the commit (as usual). If you
want to combine multiple previous commits into a single new one, use
@kbd{a} to apply them all to your working tree, and then commit them
together.
Magit has no explicit support for rewriting merge commits. It will
happily include merge commits in the list of pending commits, but
there is no way of replaying them automatically. You have to redo the
merge explicitly.
You can also use @kbd{v} to revert a commit when you have changed your
mind. This will change the @code{.} mark back to @code{*}.
Once you are done with the rewrite, type @kbd{r s} to remove the book
keeping information from the status buffer.
If you rather wish to start over, type @kbd{r a}. This will abort the
rewriting, resetting the current head back to the value it had before
the rewrite was started with @kbd{r b}.
Typing @kbd{r f} will @emph{finish} the rewrite: it will apply all
unused commits one after the other, as if you would use @kbd{A} with
all of them.
You can change the @kbd{*} and @kbd{.} marks of a pending commit
explicitly with @kbd{r *} and @kbd{r .}.
In addition to a list of pending commits, the status buffer will show
the @emph{Pending changes}. This section shows the diff between the
original head and the current head. You can use it to review the
changes that you still need to rewrite, and you can apply hunks from
it, like from any other diff.
@node Pushing and Pulling
@chapter Pushing and Pulling
Magit will run @code{git push} when you type @kbd{P P}. If you give
a prefix argument to @kbd{P P}, you will be prompted for the repository
to push to. When no default remote repository has been configured yet
for the current branch, you will be prompted as well. Typing @kbd{P P}
will only push the current branch to the remote. In other words, it
will run @code{git push <remote> <branch>}. The branch will be created
in the remote if it doesn't exist already. The local branch will be
configured so that it pulls from the new remote branch. If you give
a double prefix argument to @kbd{P P}, you will be prompted in addition
for the target branch to push to. In other words, it will run @code{git
push <remote> <branch>:<target>}.
Typing @kbd{f f} will run @code{git fetch}. It will prompt for the name
of the remote to update if there is no default one. Typing @kbd{f o}
will always prompt for the remote. Typing @kbd{F F} will run @code{git
pull}. When you don't have a default branch configured to be pulled
into the current one, you will be asked for it.
If there is a default remote repository for the current branch, Magit
will show that repository in the status buffer header.
In this case, the status buffer will also have a @emph{Unpushed
commits} section that shows the commits on your current head that are
not in the branch named @code{<remote>/<branch>}. This section works
just like the history buffer: you can see details about a commit with
@kbd{RET}, compare two of them with @kbd{.} and @kbd{=}, and you can
reset your current head to one of them with @kbd{x}, for example. If
you want to push the changes then type @kbd{P P}.
When the remote branch has changes that are not in the current branch,
Magit shows them in a section called @emph{Unpulled changes}. Typing
@kbd{F F} will fetch and merge them into the current branch.
@node Submodules
@chapter Submodules
@table @kbd
@item o u
Update the submodules, with a prefix argument it will also initialize them.
@item o i
Initialize the submodules.
@item o b
Update and initialize the submodules in one go (same as C-u o u).
@item o s
Synchronizes submodules' remote URL configuration setting to the value
specified in .gitmodules.
@end table
@node Bisecting
@chapter Bisecting
Magit supports bisecting by showing how many revisions and steps are
left to be tested in the status buffer. You can control the bisect
session from both the status and from log buffers with the @kbd{B} key
menu.
Typing @kbd{B s} will start a bisect session. You will be prompted
for a revision that is known to be bad (defaults to @emph{HEAD}) and
for a revision that is known to be good (defaults to the revision at
point if there is one). git will select a revision for you to test,
and Magit will update its status buffer accordingly.
You can tell git that the current revision is good with @kbd{B g},
that it is bad with @kbd{B b} or that git should skip it with @kbd{B
k}. You can also tell git to go into full automatic mode by giving it
the name of a script to run for each revision to test with @kbd{B u}.
The current status can be shown as a log with @kbd{B l}. It contains
the revisions that have already been tested and your decisions about
their state.
The revisions left to test can be visualized in gitk with @kbd{B v}.
When you're finished bisecting you have to reset the session with
@kbd{B r}.
@node Finding commits not merged upstream
@chapter Finding commits not merged upstream
One of the comforts of git is that it can tell you which commits have
been merged upstream but not locally and vice versa. Git's
sub-command for this is @code{cherry} (not to be confused with
@code{cherry-pick}). Magit has support for this by invoking
@code{magit-cherry} which is bound to @kbd{y} by default.
Magit will then ask you first for the upstream revision (which
defaults to the currently tracked remote branch if any) and the head
revision (which defaults to the current branch) to use in the
comparison. You will then see a new buffer in which all commits are
listed with a directional marker, their revision and the commit
message's first line. The directional marker is either @code{+}
indicating a commit that's present in upstream but not in head or
@code{-} which indicates a commit present in head but not in upstream.
From this list you can use the usual key bindings for cherry-picking
individual commits (@kbd{a} for cherry-picking without committing and
@kbd{A} for the same plus the automatic commit). The buffer is
refreshed automatically after each cherry-pick.
@node Using Magit Extensions
@chapter Magit Extensions
@menu
* Activating extensions::
* Interfacing with Subversion::
* Interfacing with Topgit::
* Interfacing with StGit::
@end menu
@node Activating extensions
@section Activating extensions
Magit comes with a couple of shipped extensions that allow interaction
with @code{git-svn}, @code{topgit} and @code{stgit}. See following
sections for specific details on how to use them.
Extensions can be activated globally or on a per-repository basis. Since
those extensions are implemented as minor modes, one can use for example
@kbd{M-x magit-topgit-mode} to toggle the @code{topgit} extension,
making the corresponding section and commands (un)available.
In order to do that automatically (and for every repository), one can
use for example:
@example
(add-hook 'magit-mode-hook 'turn-on-magit-topgit)
@end example
Magit also allows configuring different extensions, based on the git
repository configuration.
@example
(add-hook 'magit-mode-hook 'magit-load-config-extensions)
@end example
This will read git configuration variables and activate the
relevant extensions.
For example, after running the following commands, the @code{topgit}
extension will be loaded for every repository, while the @code{svn} one
will be loaded only for the current one.
@example
$ git config --global --add magit.extension topgit
$ git config --add magit.extension svn
@end example
Note the @code{--add} flag, which means that each extension gets its own
line in the @code{config} file.
@node Interfacing with Subversion
@section Interfacing with Subversion
Typing @kbd{N r} runs @code{git svn rebase}, typing @kbd{N c} runs
@code{git svn dcommit} and typing @kbd{N f} runs @code{git svn fetch}.
@kbd{N s} will prompt you for a (numeric, Subversion) revision and
then search for a corresponding Git sha1 for the commit. This is
limited to the path of the remote Subversion repository. With a prefix
(@kbd{C-u N s} the user will also be prompted for a branch to search
in.
@node Interfacing with Topgit
@section Interfacing with Topgit
@uref{http://repo.or.cz/r/topgit.git, Topgit} is a patch queue manager
that aims at being close as possible to raw Git, which makes it easy
to use with Magit. In particular, it does not require to use a
different set of commands for ``commit'', ``update'', and other
operations.
@file{magit-topgit.el} provides basic integration with Magit, mostly by
providing a ``Topics'' section.
Topgit branches can be created the regular way, by using a ``t/'' prefix
by convention. So, creating a ``t/foo'' branch will actually populate
the ``Topics'' section with one more branch after committing
@file{.topdeps} and @file{.topmsg}.
Also, the way we pull (see @ref{Pushing and Pulling}) such a branch is
slightly different, since it requires updating the various dependencies
of that branch. This should be mostly transparent, except in case
of conflicts.