File: magit.texi

package info (click to toggle)
magit 2.99.0.git0957.ge8c7bd03-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,716 kB
  • sloc: lisp: 24,020; makefile: 523; sh: 16
file content (11513 lines) | stat: -rw-r--r-- 394,035 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
\input texinfo    @c -*- texinfo -*-
@c %**start of header
@setfilename magit.info
@settitle Magit User Manual
@documentencoding UTF-8
@documentlanguage en
@c %**end of header

@copying
@quotation
Copyright (C) 2015-2020 Jonas Bernoulli <jonas@@bernoul.li>

You can redistribute this document and/or modify it under the terms
of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any
later version.

This document is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE@.  See the GNU
General Public License for more details.

@end quotation
@end copying

@dircategory Emacs
@direntry
* Magit: (magit).       Using Git from Emacs with Magit.
@end direntry

@finalout
@titlepage
@title Magit User Manual
@subtitle for version 2.90.1 (v2.90.1-954-g509e97b7+1)
@author Jonas Bernoulli
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage

@contents

@ifnottex
@node Top
@top Magit User Manual

Magit is an interface to the version control system Git, implemented
as an Emacs package.  Magit aspires to be a complete Git porcelain.
While we cannot (yet) claim that Magit wraps and improves upon each
and every Git command, it is complete enough to allow even experienced
Git users to perform almost all of their daily version control tasks
directly from within Emacs.  While many fine Git clients exist, only
Magit and Git itself deserve to be called porcelains.

@noindent
This manual is for Magit version 2.90.1 (v2.90.1-954-g509e97b7+1).

@quotation
Copyright (C) 2015-2020 Jonas Bernoulli <jonas@@bernoul.li>

You can redistribute this document and/or modify it under the terms
of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any
later version.

This document is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE@.  See the GNU
General Public License for more details.

@end quotation
@end ifnottex

@menu
* Introduction::
* Installation::
* Getting Started::
* Interface Concepts::
* Inspecting::
* Manipulating::
* Transferring::
* Miscellaneous::
* Customizing::
* Plumbing::
* FAQ::
* Debugging Tools::
* Keystroke Index::
* Command Index::
* Function Index::
* Variable Index::

@detailmenu
--- The Detailed Node Listing ---

Installation

* Installing from Melpa::
* Installing from the Git Repository::
* Post-Installation Tasks::

Interface Concepts

* Modes and Buffers::
* Sections::
* Transient Commands::
* Transient Arguments and Buffer Variables::
* Completion, Confirmation and the Selection: Completion Confirmation and the Selection. 
* Running Git::

Modes and Buffers

* Switching Buffers::
* Naming Buffers::
* Quitting Windows::
* Automatic Refreshing of Magit Buffers::
* Automatic Saving of File-Visiting Buffers::
* Automatic Reverting of File-Visiting Buffers::


Sections

* Section Movement::
* Section Visibility::
* Section Hooks::
* Section Types and Values::
* Section Options::


Completion, Confirmation and the Selection

* Action Confirmation::
* Completion and Confirmation::
* The Selection::
* The hunk-internal region::
* Support for Completion Frameworks::
* Additional Completion Options::


Running Git

* Viewing Git Output::
* Git Process Status::
* Running Git Manually::
* Git Executable::
* Global Git Arguments::


Inspecting

* Status Buffer::
* Repository List::
* Logging::
* Diffing::
* Ediffing::
* References Buffer::
* Bisecting::
* Visiting Files and Blobs::
* Blaming::

Status Buffer

* Status Sections::
* Status Header Sections::
* Status Module Sections::
* Status Options::


Logging

* Refreshing Logs::
* Log Buffer::
* Log Margin::
* Select from Log::
* Reflog::
* Cherries::


Diffing

* Refreshing Diffs::
* Commands Available in Diffs::
* Diff Options::
* Revision Buffer::


References Buffer

* References Sections::


Visiting Files and Blobs

* General-Purpose Visit Commands::
* Visiting Files and Blobs from a Diff::


Manipulating

* Creating Repository::
* Cloning Repository::
* Staging and Unstaging::
* Applying::
* Committing::
* Branching::
* Merging::
* Resolving Conflicts::
* Rebasing::
* Cherry Picking::
* Resetting::
* Stashing::

Staging and Unstaging

* Staging from File-Visiting Buffers::


Committing

* Initiating a Commit::
* Editing Commit Messages::


Branching

* The Two Remotes::
* Branch Commands::
* Branch Git Variables::
* Auxiliary Branch Commands::


Rebasing

* Editing Rebase Sequences::
* Information About In-Progress Rebase::


Cherry Picking

* Reverting::


Transferring

* Remotes::
* Fetching::
* Pulling::
* Pushing::
* Plain Patches::
* Maildir Patches::

Remotes

* Remote Commands::
* Remote Git Variables::


Miscellaneous

* Tagging::
* Notes::
* Submodules::
* Subtree::
* Worktree::
* Common Commands::
* Wip Modes::
* Minor Mode for Buffers Visiting Files::
* Minor Mode for Buffers Visiting Blobs::

Submodules

* Listing Submodules::
* Submodule Transient::


Wip Modes

* Wip Graph::
* Legacy Wip Modes::


Customizing

* Per-Repository Configuration::
* Essential Settings::

Essential Settings

* Safety::
* Performance::


Plumbing

* Calling Git::
* Section Plumbing::
* Refreshing Buffers::
* Conventions::

Calling Git

* Getting a Value from Git::
* Calling Git for Effect::


Section Plumbing

* Creating Sections::
* Section Selection::
* Matching Sections::


Conventions

* Theming Faces::


FAQ

* FAQ - How to @dots{}?::
* FAQ - Issues and Errors::

FAQ - How to @dots{}?

* How to show git's output?::
* How to install the gitman info manual?::
* How to show diffs for gpg-encrypted files?::
* How does branching and pushing work?::
* Can Magit be used as @code{ediff-version-control-package}?::


FAQ - Issues and Errors

* Magit is slow::
* I changed several thousand files at once and now Magit is unusable::
* I am having problems committing::
* I am using MS Windows and cannot push with Magit::
* I am using OS X and SOMETHING works in shell, but not in Magit: I am using OS X and SOMETHING works in shell but not in Magit. 
* Expanding a file to show the diff causes it to disappear::
* Point is wrong in the @code{COMMIT_EDITMSG} buffer::
* The mode-line information isn't always up-to-date::
* A branch and tag sharing the same name breaks SOMETHING::
* My Git hooks work on the command-line but not inside Magit::
* @code{git-commit-mode} isn't used when committing from the command-line::
* Point ends up inside invisible text when jumping to a file-visiting buffer::


@end detailmenu
@end menu

@node Introduction
@chapter Introduction

Magit is an interface to the version control system Git, implemented
as an Emacs package.  Magit aspires to be a complete Git porcelain.
While we cannot (yet) claim that Magit wraps and improves upon each
and every Git command, it is complete enough to allow even experienced
Git users to perform almost all of their daily version control tasks
directly from within Emacs.  While many fine Git clients exist, only
Magit and Git itself deserve to be called porcelains.

Staging and otherwise applying changes is one of the most important
features in a Git porcelain and here Magit outshines anything else,
including Git itself.  Git's own staging interface (@code{git add --patch})
is so cumbersome that many users only use it in exceptional cases.
In Magit staging a hunk or even just part of a hunk is as trivial as
staging all changes made to a file.

The most visible part of Magit's interface is the status buffer, which
displays information about the current repository.  Its content is
created by running several Git commands and making their output
actionable.  Among other things, it displays information about the
current branch, lists unpulled and unpushed changes and contains
sections displaying the staged and unstaged changes.  That might sound
noisy, but, since sections are collapsible, it's not.

To stage or unstage a change one places the cursor on the change and
then types @code{s} or @code{u}.  The change can be a file or a hunk, or when the
region is active (i.e. when there is a selection) several files or
hunks, or even just part of a hunk.  The change or changes that these
commands - and many others - would act on are highlighted.

Magit also implements several other "apply variants" in addition to
staging and unstaging.  One can discard or reverse a change, or
apply it to the working tree.  Git's own porcelain only supports this
for staging and unstaging and you would have to do something like @code{git
diff ... | ??? | git apply ...} to discard, revert, or apply a single
hunk on the command line.  In fact that's exactly what Magit does
internally (which is what lead to the term "apply variants").

Magit isn't just for Git experts, but it does assume some prior
experience with Git as well as Emacs.  That being said, many users
have reported that using Magit was what finally taught them what Git
is capable of and how to use it to its fullest.  Other users
wished they had switched to Emacs sooner so that they would have
gotten their hands on Magit earlier.

While one has to know the basic features of Emacs to be able to make
full use of Magit, acquiring just enough Emacs skills doesn't take
long and is worth it, even for users who prefer other editors.  Vim
users are advised to give @uref{https://bitbucket.org/lyro/evil/wiki/Home, Evil}, the "Extensible VI Layer for Emacs",
and @uref{https://github.com/syl20bnr/spacemacs, Spacemacs}, an "Emacs starter-kit focused on Evil" a try.

Magit provides a consistent and efficient Git porcelain.  After a
short learning period, you will be able to perform most of your daily
version control tasks faster than you would on the command line.  You
will likely also start using features that seemed too daunting in the
past.

Magit fully embraces Git.  It exposes many advanced features using a
simple but flexible interface instead of only wrapping the trivial
ones like many GUI clients do.  Of course Magit supports logging,
cloning, pushing, and other commands that usually don't fail in
spectacular ways; but it also supports tasks that often cannot be
completed in a single step.  Magit fully supports tasks such as
merging, rebasing, cherry-picking, reverting, and blaming by not only
providing a command to initiate these tasks but also by displaying
context sensitive information along the way and providing commands
that are useful for resolving conflicts and resuming the sequence
after doing so.

Magit wraps and in many cases improves upon at least the following Git
porcelain commands: @code{add}, @code{am}, @code{bisect}, @code{blame}, @code{branch}, @code{checkout}, @code{cherry},
@code{cherry-pick}, @code{clean}, @code{clone}, @code{commit}, @code{config}, @code{describe}, @code{diff}, @code{fetch},
@code{format-patch}, @code{init}, @code{log}, @code{merge}, @code{merge-tree}, @code{mv}, @code{notes}, @code{pull}, @code{rebase},
@code{reflog}, @code{remote}, @code{request-pull}, @code{reset}, @code{revert}, @code{rm}, @code{show}, @code{stash},
@code{submodule}, @code{subtree}, @code{tag}, and @code{worktree.}  Many more Magit porcelain
commands are implemented on top of Git plumbing commands.

@node Installation
@chapter Installation

Magit can be installed using Emacs' package manager or manually from
its development repository.

@menu
* Installing from Melpa::
* Installing from the Git Repository::
* Post-Installation Tasks::
@end menu

@node Installing from Melpa
@section Installing from Melpa

Magit is available from Melpa and Melpa-Stable.  If you haven't used
Emacs' package manager before, then it is high time you familiarize
yourself with it by reading the documentation in the Emacs manual, see
@ref{Packages,,,emacs,}.  Then add one of the archives to
@code{package-archives}:

@itemize
@item
To use Melpa:
@end itemize

@lisp
(require 'package)
(add-to-list 'package-archives
             '("melpa" . "http://melpa.org/packages/") t)
@end lisp

@itemize
@item
To use Melpa-Stable:
@end itemize

@lisp
(require 'package)
(add-to-list 'package-archives
             '("melpa-stable" . "http://stable.melpa.org/packages/") t)
@end lisp

Once you have added your preferred archive, you need to update the
local package list using:

@example
M-x package-refresh-contents RET
@end example

Once you have done that, you can install Magit and its dependencies
using:

@example
M-x package-install RET magit RET
@end example

Now see @ref{Post-Installation Tasks}.

@node Installing from the Git Repository
@section Installing from the Git Repository

Magit depends on the @code{dash}, @code{transient} and @code{with-editor} libraries
which are available from Melpa and Melpa-Stable.  Install them using
@code{M-x package-install RET <package> RET}.  Of course you may also install
them manually from their repository.

Then clone the Magit repository:

@example
$ git clone https://github.com/magit/magit.git ~/.emacs.d/site-lisp/magit
$ cd ~/.emacs.d/site-lisp/magit
@end example

Then compile the libraries and generate the info manuals:

@example
$ make
@end example

If you haven't installed @code{dash}, @code{transient} and @code{with-editor} from
Melpa or at @code{/path/to/magit/../<package>}, then you have to tell @code{make}
where to find them.  To do so create the file @code{/path/to/magit/config.mk}
with the following content before running @code{make}:

@example
LOAD_PATH  = -L /path/to/magit/lisp
LOAD_PATH += -L /path/to/dash
LOAD_PATH += -L /path/to/transient
LOAD_PATH += -L /path/to/with-editor
@end example

Finally add this to your init file:

@lisp
(add-to-list 'load-path "~/.emacs.d/site-lisp/magit/lisp")
(require 'magit)

(with-eval-after-load 'info
  (info-initialize)
  (add-to-list 'Info-directory-list
               "~/.emacs.d/site-lisp/magit/Documentation/"))
@end lisp

Note that you have to add the @code{lisp} subdirectory to the @code{load-path}, not
the top-level of the repository, and that elements of @code{load-path} should
not end with a slash, while those of @code{Info-directory-list} should.

Instead of requiring the feature @code{magit}, you could load just the
autoload definitions, by loading the file @code{magit-autoloads.el}.

@lisp
(load "/path/to/magit/lisp/magit-autoloads")
@end lisp

Instead of running Magit directly from the repository by adding that
to the @code{load-path}, you might want to instead install it in some other
directory using @code{sudo make install} and setting @code{load-path} accordingly.

To update Magit use:

@example
$ git pull
$ make
@end example

At times it might be necessary to run @code{make clean all} instead.

To view all available targets use @code{make help}.

Now see @ref{Post-Installation Tasks}.

@node Post-Installation Tasks
@section Post-Installation Tasks

After installing Magit you should verify that you are indeed using the
Magit, Git, and Emacs releases you think you are using.  It's best to
restart Emacs before doing so, to make sure you are not using an
outdated value for @code{load-path}.

@example
M-x magit-version RET
@end example

should display something like

@example
Magit 2.8.0, Git 2.10.2, Emacs 25.1.1, gnu/linux
@end example

Then you might also want to read about options that many users likely
want to customize.  See @ref{Essential Settings}.

To be able to follow cross references to Git manpages found in this
manual, you might also have to manually install the @code{gitman} info manual,
or advice @code{Info-follow-nearest-node} to instead open the actual manpage.
See @ref{How to install the gitman info manual?}.

If you are completely new to Magit then see @ref{Getting Started}.

If you run into problems, then please see the @ref{FAQ}.  Also see the
@ref{Debugging Tools}.

And last but not least please consider making a donation, to ensure
that I can keep working on Magit.  See @uref{https://magit.vc/donations}.
for various donation options.

@node Getting Started
@chapter Getting Started

This short tutorial describes the most essential features that many
Magitians use on a daily basis.  It only scratches the surface but
should be enough to get you started.

IMPORTANT: It is safest if you clone some repository just for this
tutorial.  Alternatively you can use an existing local repository, but
if you do that, then you should commit all uncommitted changes before
proceeding.

To display information about the current Git repository, type @code{M-x
magit-status RET}.  You will be using this command a lot, and should
therefore give it a global key binding.  This is what we recommend:

@lisp
(global-set-key (kbd "C-x g") 'magit-status)
@end lisp

Most Magit commands are commonly invoked from the status buffer.  It
can be considered the primary interface for interacting with Git using
Magit.  Many other Magit buffers may exist at a given time, but they
are often created from this buffer.

Depending on what state your repository is in, this buffer may contain
sections titled "Staged changes", "Unstaged changes", "Unmerged into
origin/master", "Unpushed to origin/master", and many others.

Since we are starting from a safe state, which you can easily return
to (by doing a @code{git reset --hard PRE-MAGIT-STATE}), there currently are
no staged or unstaged changes.  Edit some files and save the changes.
Then go back to the status buffer, while at the same time refreshing
it, by typing @code{C-x g}.  (When the status buffer, or any Magit buffer for
that matter, is the current buffer, then you can also use just @code{g} to
refresh it).

Move between sections using @code{p} and @code{n}.  Note that the bodies of some
sections are hidden.  Type @code{TAB} to expand or collapse the section at
point.  You can also use @code{C-tab} to cycle the visibility of the current
section and its children.  Move to a file section inside the section
named "Unstaged changes" and type @code{s} to stage the changes you have made
to that file.  That file now appears under "Staged changes".

Magit can stage and unstage individual hunks, not just complete files.
Move to the file you have just staged, expand it using @code{TAB}, move to
one of the hunks using @code{n}, and unstage just that by typing @code{u}.  Note how
the staging (@code{s}) and unstaging (@code{u}) commands operate on the change at
point.  Many other commands behave the same way.

You can also un-/stage just part of a hunk.  Inside the body of a hunk
section (move there using @code{C-n}), set the mark using @code{C-SPC} and move down
until some added and/or removed lines fall inside the region but not
all of them.  Again type @code{s} to stage.

It is also possible to un-/stage multiple files at once.  Move to a
file section, type @code{C-SPC}, move to the next file using @code{n}, and then @code{s} to
stage both files.  Note that both the mark and point have to be on the
headings of sibling sections for this to work.  If the region looks
like it does in other buffers, then it doesn't select Magit sections
that can be acted on as a unit.

And then of course you want to commit your changes.  Type @code{c}.  This
shows the available commit commands and arguments in a buffer at the
bottom of the frame.  Each command and argument is prefixed with the
key that invokes/sets it.  Do not worry about this for now.  We want
to create a "normal" commit, which is done by typing @code{c} again.

Now two new buffers appear.  One is for writing the commit message,
the other shows a diff with the changes that you are about to
committed.  Write a message and then type @code{C-c C-c} to actually create
the commit.

You probably don't want to push the commit you just created because
you just committed some random changes, but if that is not the case
you could push it by typing @code{P} to show all the available push commands
and arguments and then @code{p} to push to a branch with the same name as the
local branch onto the remote configured as the push-remote.  (If the
push-remote is not configured yet, then you would first be prompted
for the remote to push to.)

So far we have mentioned the commit, push, and log transient prefix
commands.  These are probably among the transients you will be using
the most, but many others exist.  To show a transient that lists all
other transients (as well as the various apply commands and some other
essential commands), type @code{h}.  Try a few.

The key bindings in that transient correspond to the bindings in Magit
buffers, including but not limited to the status buffer.  So you could
type @code{h d} to bring up the diff transient, but once you remember that
"d" stands for "diff", you would usually do so by just typing @code{d}.  But
this "prefix of prefixes" is useful even once you have memorized all
the bindings, as it can provide easy access to Magit commands from
non-Magit buffers.  You should create a global key binding for this
command too:

@lisp
(global-set-key (kbd "C-x M-g") 'magit-dispatch)
@end lisp

In the same vein, you might also want to enable @code{global-magit-file-mode}
to get some more Magit key bindings in regular file-visiting buffers
(see @ref{Minor Mode for Buffers Visiting Files}).

It is not necessary that you do so now, but if you stick with Magit,
then it is highly recommended that you read the next section too.

@node Interface Concepts
@chapter Interface Concepts

@menu
* Modes and Buffers::
* Sections::
* Transient Commands::
* Transient Arguments and Buffer Variables::
* Completion, Confirmation and the Selection: Completion Confirmation and the Selection. 
* Running Git::
@end menu

@node Modes and Buffers
@section Modes and Buffers

Magit provides several major-modes.  For each of these modes there
usually exists only one buffer per repository.  Separate modes and
thus buffers exist for commits, diffs, logs, and some other things.

Besides these special purpose buffers, there also exists an overview
buffer, called the @strong{status buffer}.  It's usually from this buffer that
the user invokes Git commands, or creates or visits other buffers.

In this manual we often speak about "Magit buffers".  By that we mean
buffers whose major-modes derive from @code{magit-mode}.

@table @asis
@kindex M-x magit-toggle-buffer-lock
@cindex magit-toggle-buffer-lock
@item @kbd{M-x magit-toggle-buffer-lock} @tie{}@tie{}@tie{}@tie{}(@code{magit-toggle-buffer-lock})

This command locks the current buffer to its value or if the buffer
is already locked, then it unlocks it.

Locking a buffer to its value prevents it from being reused to
display another value.  The name of a locked buffer contains its
value, which allows telling it apart from other locked buffers and
the unlocked buffer.

Not all Magit buffers can be locked to their values; for example, it
wouldn't make sense to lock a status buffer.

There can only be a single unlocked buffer using a certain
major-mode per repository.  So when a buffer is being unlocked and
another unlocked buffer already exists for that mode and repository,
then the former buffer is instead deleted and the latter is
displayed in its place.
@end table

@menu
* Switching Buffers::
* Naming Buffers::
* Quitting Windows::
* Automatic Refreshing of Magit Buffers::
* Automatic Saving of File-Visiting Buffers::
* Automatic Reverting of File-Visiting Buffers::
@end menu

@node Switching Buffers
@subsection Switching Buffers

@defun magit-display-buffer buffer &optional display-function

This function is a wrapper around @code{display-buffer} and is used to
display any Magit buffer.  It displays BUFFER in some window and,
unlike @code{display-buffer}, also selects that window, provided
@code{magit-display-buffer-noselect} is @code{nil}.  It also runs the hooks
mentioned below.

If optional DISPLAY-FUNCTION is non-nil, then that is used to
display the buffer.  Usually that is @code{nil} and the function specified
by @code{magit-display-buffer-function} is used.
@end defun

@defvar magit-display-buffer-noselect

When this is non-nil, then @code{magit-display-buffer} only displays the
buffer but forgoes also selecting the window.  This variable should
not be set globally, it is only intended to be let-bound, by code
that automatically updates "the other window".  This is used for
example when the revision buffer is updated when you move inside the
log buffer.
@end defvar

@defopt magit-display-buffer-function

The function specified here is called by @code{magit-display-buffer} with
one argument, a buffer, to actually display that buffer.  This
function should call @code{display-buffer} with that buffer as first and a
list of display actions as second argument.

Magit provides several functions, listed below, that are suitable
values for this option.  If you want to use different rules, then a
good way of doing that is to start with a copy of one of these
functions and then adjust it to your needs.

Instead of using a wrapper around @code{display-buffer}, that function
itself can be used here, in which case the display actions have to
be specified by adding them to @code{display-buffer-alist} instead.

To learn about display actions, see @ref{Choosing Window,,,elisp,}.
@end defopt

@defun magit-display-buffer-traditional buffer

This function is the current default value of the option
@code{magit-display-buffer-function}.  Before that option and this function
were added, the behavior was hard-coded in many places all over the
code base but now all the rules are contained in this one function
(except for the "noselect" special case mentioned above).
@end defun

@defun magit-display-buffer-same-window-except-diff-v1

This function displays most buffers in the currently selected
window.  If a buffer's mode derives from @code{magit-diff-mode} or
@code{magit-process-mode}, it is displayed in another window.
@end defun

@defun magit-display-buffer-fullframe-status-v1

This function fills the entire frame when displaying a status
buffer.  Otherwise, it behaves like
@code{magit-display-buffer-traditional}.
@end defun

@defun magit-display-buffer-fullframe-status-topleft-v1

This function fills the entire frame when displaying a status
buffer.  It behaves like @code{magit-display-buffer-fullframe-status-v1}
except that it displays buffers that derive from @code{magit-diff-mode}
or @code{magit-process-mode} to the top or left of the current buffer
rather than to the bottom or right.  As a result, Magit buffers tend
to pop up on the same side as they would if
@code{magit-display-buffer-traditional} were in use.
@end defun

@defun magit-display-buffer-fullcolumn-most-v1

This function displays most buffers so that they fill the entire
height of the frame.  However, the buffer is displayed in another
window if (1) the buffer's mode derives from @code{magit-process-mode},
or (2) the buffer's mode derives from @code{magit-diff-mode}, provided
that the mode of the current buffer derives from @code{magit-log-mode} or
@code{magit-cherry-mode}.
@end defun

@defopt magit-pre-display-buffer-hook

This hook is run by @code{magit-display-buffer} before displaying the
buffer.
@end defopt

@defun magit-save-window-configuration

This function saves the current window configuration.  Later when
the buffer is buried, it may be restored by
@code{magit-restore-window-configuration}.
@end defun

@defopt magit-post-display-buffer-hook

This hook is run by @code{magit-display-buffer} after displaying the
buffer.
@end defopt

@defun magit-maybe-set-dedicated

This function remembers if a new window had to be created to display
the buffer, or whether an existing window was reused.  This
information is later used by @code{magit-mode-quit-window}, to determine
whether the window should be deleted when its last Magit buffer is
buried.
@end defun

@node Naming Buffers
@subsection Naming Buffers

@defopt magit-generate-buffer-name-function

The function used to generate the names of Magit buffers.

Such a function should take the options @code{magit-uniquify-buffer-names}
as well as @code{magit-buffer-name-format} into account.  If it doesn't,
then should be clearly stated in the doc-string.  And if it supports
%-sequences beyond those mentioned in the doc-string of the option
@code{magit-buffer-name-format}, then its own doc-string should describe
the additions.
@end defopt

@defun magit-generate-buffer-name-default-function mode

This function returns a buffer name suitable for a buffer whose
major-mode is MODE and which shows information about the repository
in which @code{default-directory} is located.

This function uses @code{magit-buffer-name-format} and supporting all of
the %-sequences mentioned the documentation of that option.  It also
respects the option @code{magit-uniquify-buffer-names}.
@end defun

@defopt magit-buffer-name-format

The format string used to name Magit buffers.

At least the following %-sequences are supported:

@itemize
@item
@code{%m}

The name of the major-mode, but with the @code{-mode} suffix removed.


@item
@code{%M}

Like @code{%m} but abbreviate @code{magit-status-mode} as @code{magit}.


@item
@code{%v}

The value the buffer is locked to, in parentheses, or an empty
string if the buffer is not locked to a value.


@item
@code{%V}

Like @code{%v}, but the string is prefixed with a space, unless it is an
empty string.


@item
@code{%t}

The top-level directory of the working tree of the repository, or
if @code{magit-uniquify-buffer-names} is non-nil an abbreviation of that.


@item
@code{%x}

If @code{magit-uniquify-buffer-names} is nil "*", otherwise the empty
string.  Due to limitations of the @code{uniquify} package, buffer names
must end with the path.


@item
@code{%T}

Obsolete, use "%t%x" instead.  Like @code{%t}, but append an asterisk if
and only if @code{magit-uniquify-buffer-names} is nil.
@end itemize

The value should always contain @code{%m} or @code{%M}, @code{%v} or @code{%V}, and @code{%t} (or the
obsolete @code{%T}).  If @code{magit-uniquify-buffer-names} is non-nil, then the
value must end with @code{%t} or @code{%t%x} (or the obsolete @code{%T}).  See issue
#2841.
@end defopt

@defopt magit-uniquify-buffer-names

This option controls whether the names of Magit buffers are
uniquified.  If the names are not being uniquified, then they
contain the full path of the top-level of the working tree of the
corresponding repository.  If they are being uniquified, then they
end with the basename of the top-level, or if that would conflict
with the name used for other buffers, then the names of all these
buffers are adjusted until they no longer conflict.

This is done using the @code{uniquify} package; customize its options to
control how buffer names are uniquified.
@end defopt

@node Quitting Windows
@subsection Quitting Windows

@table @asis
@kindex q
@cindex magit-mode-bury-buffer
@item @kbd{q} @tie{}@tie{}@tie{}@tie{}(@code{magit-mode-bury-buffer})

This command buries the current Magit buffer.

With a prefix argument, it instead kills the buffer.  With a double
prefix argument, also kills all other Magit buffers associated with
the current project.

@end table

@defopt magit-bury-buffer-function

The function used to actually bury or kill the current buffer.

@code{magit-mode-bury-buffer} calls this function with one argument.  If
the argument is non-nil, then the function has to kill the current
buffer.  Otherwise it has to bury it alive.  The default value
currently is @code{magit-restore-window-configuration}.
@end defopt

@defun magit-restore-window-configuration kill-buffer

Bury or kill the current buffer using @code{quit-window}, which is called
with KILL-BUFFER as first and the selected window as second
argument.

Then restore the window configuration that existed right before the
current buffer was displayed in the selected frame.  Unfortunately
that also means that point gets adjusted in all the buffers, which
are being displayed in the selected frame.
@end defun

@defun magit-mode-quit-window kill-buffer

Bury or kill the current buffer using @code{quit-window}, which is called
with KILL-BUFFER as first and the selected window as second
argument.

Then, if the window was originally created to display a Magit buffer
and the buried buffer was the last remaining Magit buffer that was
ever displayed in the window, then that is deleted.
@end defun

@node Automatic Refreshing of Magit Buffers
@subsection Automatic Refreshing of Magit Buffers

After running a command which may change the state of the current
repository, the current Magit buffer and the corresponding status
buffer are refreshed. The status buffer can be automatically refreshed
whenever a buffer is saved to a file inside the respective repository
by adding a hook, like so:

@lisp
(add-hook 'after-save-hook 'magit-after-save-refresh-status t)
@end lisp

Automatically refreshing Magit buffers ensures that the displayed
information is up-to-date most of the time but can lead to a
noticeable delay in big repositories.  Other Magit buffers are not
refreshed to keep the delay to a minimum and also because doing so can
sometimes be undesirable.

Buffers can also be refreshed explicitly, which is useful in buffers
that weren't current during the last refresh and after changes were
made to the repository outside of Magit.

@table @asis
@kindex g
@cindex magit-refresh
@item @kbd{g} @tie{}@tie{}@tie{}@tie{}(@code{magit-refresh})

This command refreshes the current buffer if its major mode derives
from @code{magit-mode} as well as the corresponding status buffer.

If the option @code{magit-revert-buffers} calls for it, then it also
reverts all unmodified buffers that visit files being tracked in the
current repository.

@kindex G
@cindex magit-refresh-all
@item @kbd{G} @tie{}@tie{}@tie{}@tie{}(@code{magit-refresh-all})

This command refreshes all Magit buffers belonging to the current
repository and also reverts all unmodified buffers that visit files
being tracked in the current repository.

The file-visiting buffers are always reverted, even if
@code{magit-revert-buffers} is nil.

@end table

@defopt magit-refresh-buffer-hook

This hook is run in each Magit buffer that was refreshed during the
current refresh - normally the current buffer and the status buffer.
@end defopt

@defopt magit-refresh-status-buffer

When this option is non-nil, then the status buffer is automatically
refreshed after running git for side-effects, in addition to the
current Magit buffer, which is always refreshed automatically.

Only set this to nil after exhausting all other options to improve
performance.
@end defopt

@defun magit-after-save-refresh-status

This function is intended to be added to @code{after-save-hook}.  After
doing that the corresponding status buffer is refreshed whenever a
buffer is saved to a file inside a repository.

Note that refreshing a Magit buffer is done by re-creating its
contents from scratch, which can be slow in large repositories.  If
you are not satisfied with Magit's performance, then you should
obviously not add this function to that hook.
@end defun

@node Automatic Saving of File-Visiting Buffers
@subsection Automatic Saving of File-Visiting Buffers

File-visiting buffers are by default saved at certain points in time.
This doesn't guarantee that Magit buffers are always up-to-date, but,
provided one only edits files by editing them in Emacs and uses only
Magit to interact with Git, one can be fairly confident.  When in
doubt or after outside changes, type @code{g} (@code{magit-refresh}) to save and
refresh explicitly.

@defopt magit-save-repository-buffers

This option controls whether file-visiting buffers are saved before
certain events.

If this is non-nil then all modified file-visiting buffers belonging
to the current repository may be saved before running commands,
before creating new Magit buffers, and before explicitly refreshing
such buffers.  If this is @code{dontask} then this is done without user
intervention.  If it is @code{t} then the user has to confirm each save.
@end defopt

@node Automatic Reverting of File-Visiting Buffers
@subsection Automatic Reverting of File-Visiting Buffers

By default Magit automatically reverts buffers that are visiting files
that are being tracked in a Git repository, after they have changed on
disk.  When using Magit one often changes files on disk by running
Git, i.e. "outside Emacs", making this a rather important feature.

For example, if you discard a change in the status buffer, then that
is done by running @code{git apply --reverse ...}, and Emacs considers the
file to have "changed on disk".  If Magit did not automatically revert
the buffer, then you would have to type @code{M-x revert-buffer RET RET} in
the visiting buffer before you could continue making changes.

@defopt magit-auto-revert-mode

When this mode is enabled, then buffers that visit tracked files
are automatically reverted after the visited files change on disk.
@end defopt

@defopt global-auto-revert-mode

When this mode is enabled, then any file-visiting buffer is
automatically reverted after the visited file changes on disk.

If you like buffers that visit tracked files to be automatically
reverted, then you might also like any buffer to be reverted, not
just those visiting tracked files.  If that is the case, then enable
this mode @emph{instead of} @code{magit-auto-revert-mode}.
@end defopt

@defopt magit-auto-revert-immediately

This option controls whether Magit reverts buffers immediately.

If this is non-nil and either @code{global-auto-revert-mode} or
@code{magit-auto-revert-mode} is enabled, then Magit immediately reverts
buffers by explicitly calling @code{auto-revert-buffers} after running Git
for side-effects.

If @code{auto-revert-use-notify} is non-nil (and file notifications are
actually supported), then @code{magit-auto-revert-immediately} does not
have to be non-nil, because the reverts happen immediately anyway.

If @code{magit-auto-revert-immediately} and @code{auto-revert-use-notify} are both
@code{nil}, then reverts happen after @code{auto-revert-interval} seconds of user
inactivity.  That is not desirable.
@end defopt

@defopt auto-revert-use-notify

This option controls whether file notification functions should be
used.  Note that this variable unfortunately defaults to @code{t} even on
systems on which file notifications cannot be used.
@end defopt

@defopt magit-auto-revert-tracked-only

This option controls whether @code{magit-auto-revert-mode} only reverts
tracked files or all files that are located inside Git repositories,
including untracked files and files located inside Git's control
directory.
@end defopt

@defopt auto-revert-mode

The global mode @code{magit-auto-revert-mode} works by turning on this
local mode in the appropriate buffers (but @code{global-auto-revert-mode}
is implemented differently).  You can also turn it on or off
manually, which might be necessary if Magit does not notice that a
previously untracked file now is being tracked or vice-versa.
@end defopt

@defopt auto-revert-stop-on-user-input

This option controls whether the arrival of user input suspends the
automatic reverts for @code{auto-revert-interval} seconds.
@end defopt

@defopt auto-revert-interval

This option controls how many seconds Emacs waits for before
resuming suspended reverts.
@end defopt

@defopt auto-revert-buffer-list-filter

This option specifies an additional filter used by
@code{auto-revert-buffers} to determine whether a buffer should be reverted
or not.

This option is provided by Magit, which also advises
@code{auto-revert-buffers} to respect it.  Magit users who do not turn on
the local mode @code{auto-revert-mode} themselves, are best served by
setting the value to @code{magit-auto-revert-repository-buffer-p}.

However the default is nil, so as not to disturb users who do use the
local mode directly.  If you experience delays when running Magit
commands, then you should consider using one of the predicates
provided by Magit - especially if you also use Tramp.

Users who do turn on @code{auto-revert-mode} in buffers in which Magit
doesn't do that for them, should likely not use any filter.  Users
who turn on @code{global-auto-revert-mode}, do not have to worry about this
option, because it is disregarded if the global mode is enabled.
@end defopt

@defopt auto-revert-verbose

This option controls whether Emacs reports when a buffer has been
reverted.
@end defopt

The options with the @code{auto-revert-} prefix are located in the Custom
group named @code{auto-revert}.  The other, Magit-specific, options are
located in the @code{magit} group.

@menu
* Risk of Reverting Automatically::
@end menu

@node Risk of Reverting Automatically
@unnumberedsubsubsec Risk of Reverting Automatically

For the vast majority of users, automatically reverting file-visiting
buffers after they have changed on disk is harmless.

If a buffer is modified (i.e. it contains changes that haven't been
saved yet), then Emacs will refuse to automatically revert it.  If
you save a previously modified buffer, then that results in what is
seen by Git as an uncommitted change.  Git will then refuse to carry
out any commands that would cause these changes to be lost.  In other
words, if there is anything that could be lost, then either Git or
Emacs will refuse to discard the changes.

However, if you use file-visiting buffers as a sort of ad hoc
"staging area", then the automatic reverts could potentially cause
data loss.  So far I have heard from only one user who uses such a
workflow.

An example: You visit some file in a buffer, edit it, and save the
changes.  Then, outside of Emacs (or at least not using Magit or by
saving the buffer) you change the file on disk again.  At this point
the buffer is the only place where the intermediate version still
exists.  You have saved the changes to disk, but that has since been
overwritten.  Meanwhile Emacs considers the buffer to be unmodified
(because you have not made any changes to it since you last saved it
to the visited file) and therefore would not object to it being
automatically reverted.  At this point an Auto-Revert mode would kick
in.  It would check whether the buffer is modified and since that is
not the case it would revert it.  The intermediate version would be
lost.  (Actually you could still get it back using the @code{undo} command.)

If your workflow depends on Emacs preserving the intermediate version
in the buffer, then you have to disable all Auto-Revert modes.  But
please consider that such a workflow would be dangerous even without
using an Auto-Revert mode, and should therefore be avoided.  If Emacs
crashes or if you quit Emacs by mistake, then you would also lose the
buffer content.  There would be no autosave file still containing the
intermediate version (because that was deleted when you saved the
buffer) and you would not be asked whether you want to save the buffer
(because it isn't modified).

@node Sections
@section Sections

Magit buffers are organized into nested sections, which can be
collapsed and expanded, similar to how sections are handled in Org
mode.  Each section also has a type, and some sections also have a
value.  For each section type there can also be a local keymap, shared
by all sections of that type.

Taking advantage of the section value and type, many commands operate on
the current section, or when the region is active and selects sections
of the same type, all of the selected sections.  Commands that only
make sense for a particular section type (as opposed to just behaving
differently depending on the type) are usually bound in section type
keymaps.

@menu
* Section Movement::
* Section Visibility::
* Section Hooks::
* Section Types and Values::
* Section Options::
@end menu

@node Section Movement
@subsection Section Movement

To move within a section use the usual keys (@code{C-p}, @code{C-n}, @code{C-b}, @code{C-f} etc),
whose global bindings are not shadowed.  To move to another section use
the following commands.

@table @asis
@kindex p
@cindex magit-section-backward
@item @kbd{p} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-backward})

When not at the beginning of a section, then move to the beginning
of the current section.  At the beginning of a section, instead move
to the beginning of the previous visible section.

@kindex n
@cindex magit-section-forward
@item @kbd{n} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-forward})

Move to the beginning of the next visible section.

@kindex M-p
@cindex magit-section-backward-siblings
@item @kbd{M-p} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-backward-siblings})

Move to the beginning of the previous sibling section.  If there is
no previous sibling section, then move to the parent section
instead.

@kindex M-n
@cindex magit-section-forward-siblings
@item @kbd{M-n} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-forward-siblings})

Move to the beginning of the next sibling section.  If there is no
next sibling section, then move to the parent section instead.

@kindex ^
@cindex magit-section-up
@item @kbd{^} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-up})

Move to the beginning of the parent of the current section.
@end table

The above commands all call the hook @code{magit-section-movement-hook}.
Any of the functions listed below can be used as members of this hook.

You might want to remove some of the functions that Magit adds using
@code{add-hook}.  In doing so you have to make sure you do not attempt to
remove function that haven't even been added yet, for example:

@lisp
(with-eval-after-load 'magit-diff
  (remove-hook 'magit-section-movement-hook
               'magit-hunk-set-window-start))
@end lisp

@defvar magit-section-movement-hook

This hook is run by all of the above movement commands, after
arriving at the destination.
@end defvar

@defun magit-hunk-set-window-start

This hook function ensures that the beginning of the current section
is visible, provided it is a @code{hunk} section.  Otherwise, it does
nothing.

Loading @code{magit-diff} adds this function to the hook.
@end defun

@defun magit-section-set-window-start

This hook function ensures that the beginning of the current section
is visible, regardless of the section's type.  If you add this to
@code{magit-section-movement-hook}, then you must remove the hunk-only
variant in turn.
@end defun

@defun magit-log-maybe-show-more-commits

This hook function only has an effect in log buffers, and @code{point} is
on the "show more" section.  If that is the case, then it doubles
the number of commits that are being shown.

Loading @code{magit-log} adds this function to the hook.
@end defun

@defun magit-log-maybe-update-revision-buffer

When moving inside a log buffer, then this function updates the
revision buffer, provided it is already being displayed in another
window of the same frame.

Loading @code{magit-log} adds this function to the hook.
@end defun

@defun magit-log-maybe-update-blob-buffer

When moving inside a log buffer and another window of the same frame
displays a blob buffer, then this function instead displays the blob
buffer for the commit at point in that window.
@end defun

@defun magit-status-maybe-update-revision-buffer

When moving inside a status buffer, then this function updates the
revision buffer, provided it is already being displayed in another
window of the same frame.
@end defun

@defun magit-status-maybe-update-stash-buffer

When moving inside a status buffer, then this function updates the
stash buffer, provided it is already being displayed in another
window of the same frame.
@end defun

@defun magit-status-maybe-update-blob-buffer

When moving inside a status buffer and another window of the same
frame displays a blob buffer, then this function instead displays
the blob buffer for the commit at point in that window.
@end defun

@defun magit-stashes-maybe-update-stash-buffer

When moving inside a buffer listing stashes, then this function
updates the stash buffer, provided it is already being displayed
in another window of the same frame.
@end defun

@defopt magit-update-other-window-delay

Delay before automatically updating the other window.

When moving around in certain buffers, then certain other buffers,
which are being displayed in another window, may optionally be
updated to display information about the section at point.

When holding down a key to move by more than just one section, then
that would update that buffer for each section on the way.  To
prevent that, updating the revision buffer is delayed, and this
option controls for how long.  For optimal experience you might have
to adjust this delay and/or the keyboard repeat rate and delay of
your graphical environment or operating system.
@end defopt

@node Section Visibility
@subsection Section Visibility

Magit provides many commands for changing the visibility of sections,
but all you need to get started are the next two.

@table @asis
@kindex TAB
@cindex magit-section-toggle
@item @kbd{TAB} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-toggle})

Toggle the visibility of the body of the current section.

@kindex C-<tab>
@cindex magit-section-cycle
@item @kbd{C-<tab>} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-cycle})

Cycle the visibility of current section and its children.

@kindex M-<tab>
@cindex magit-section-cycle-diffs
@item @kbd{M-<tab>} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-cycle-diffs})

Cycle the visibility of diff-related sections in the current buffer.

@kindex S-<tab>
@cindex magit-section-cycle-global
@item @kbd{S-<tab>} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-cycle-global})

Cycle the visibility of all sections in the current buffer.

@kindex 1
@cindex magit-section-show-level-1
@item @kbd{1} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-show-level-1})
@kindex 2
@cindex magit-section-show-level-2
@item @kbd{2} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-show-level-2})
@kindex 3
@cindex magit-section-show-level-3
@item @kbd{3} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-show-level-3})
@kindex 4
@cindex magit-section-show-level-4
@item @kbd{4} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-show-level-4})

Show sections surrounding the current section up to level N@.

@kindex M-1
@cindex magit-section-show-level-1-all
@item @kbd{M-1} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-show-level-1-all})
@kindex M-2
@cindex magit-section-show-level-2-all
@item @kbd{M-2} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-show-level-2-all})
@kindex M-3
@cindex magit-section-show-level-3-all
@item @kbd{M-3} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-show-level-3-all})
@kindex M-4
@cindex magit-section-show-level-4-all
@item @kbd{M-4} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-show-level-4-all})

Show all sections up to level N@.
@end table

Some functions, which are used to implement the above commands, are
also exposed as commands themselves.  By default no keys are bound to
these commands, as they are generally perceived to be much less
useful.  But your mileage may vary.

@cindex magit-section-show
@deffn Command magit-section-show

Show the body of the current section.
@end deffn

@cindex magit-section-hide
@deffn Command magit-section-hide

Hide the body of the current section.
@end deffn

@cindex magit-section-show-headings
@deffn Command magit-section-show-headings

Recursively show headings of children of the current section.  Only
show the headings.  Previously shown text-only bodies are hidden.
@end deffn

@cindex magit-section-show-children
@deffn Command magit-section-show-children

Recursively show the bodies of children of the current section.
With a prefix argument show children down to the level of the
current section, and hide deeper children.
@end deffn

@cindex magit-section-hide-children
@deffn Command magit-section-hide-children

Recursively hide the bodies of children of the current section.
@end deffn

@cindex magit-section-toggle-children
@deffn Command magit-section-toggle-children

Toggle visibility of bodies of children of the current section.
@end deffn

When a buffer is first created then some sections are shown expanded
while others are not.  This is hard coded.  When a buffer is refreshed
then the previous visibility is preserved.  The initial visibility of
certain sections can also be overwritten using the hook
@code{magit-section-set-visibility-hook}.

@defopt magit-section-initial-visibility-alist

This options can be used to override the initial visibility of
sections.  In the future it will also be used to define the
defaults, but currently a section's default is still hardcoded.

The value is an alist.  Each element maps a section type or lineage
to the initial visibility state for such sections.  The state has to
be one of @code{show} or @code{hide}, or a function that returns one of these
symbols.  A function is called with the section as the only argument.

Use the command @code{magit-describe-section-briefly} to determine a
section's lineage or type.  The vector in the output is the section
lineage and the type is the first element of that vector.  Wildcards
can be used, see @code{magit-section-match}.
@end defopt

@defopt magit-section-cache-visibility

This option controls for which sections the previous visibility
state should be restored if a section disappears and later appears
again.  The value is a boolean or a list of section types.  If t,
then the visibility of all sections is cached.  Otherwise this is
only done for sections whose type matches one of the listed types.

This requires that the function @code{magit-section-cached-visibility} is
a member of @code{magit-section-set-visibility-hook}.
@end defopt

@defvar magit-section-set-visibility-hook

This hook is run when first creating a buffer and also when
refreshing an existing buffer, and is used to determine the
visibility of the section currently being inserted.

Each function is called with one argument, the section being
inserted.  It should return @code{hide} or @code{show}, or to leave the visibility
undefined @code{nil}.  If no function decides on the visibility and the
buffer is being refreshed, then the visibility is preserved; or if
the buffer is being created, then the hard coded default is used.

Usually this should only be used to set the initial visibility but
not during refreshes.  If @code{magit-insert-section--oldroot} is non-nil,
then the buffer is being refreshed and these functions should
immediately return @code{nil}.
@end defvar

@defopt magit-section-visibility-indicator

This option controls whether and how to indicate that a section can
be expanded/collapsed.

If nil, then no visibility indicators are shown.  Otherwise the
value has to have one of these two forms:

@itemize
@item
@code{(EXPANDABLE-BITMAP . COLLAPSIBLE-BITMAP)}

Both values have to be variables whose values are fringe
bitmaps.  In this case every section that can be expanded
or collapsed gets an indicator in the left fringe.

To provide extra padding around the indicator, set
@code{left-fringe-width} in @code{magit-mode-hook}, e.g.:

@lisp
(add-hook 'magit-mode-hook (lambda ()
                             (setq left-fringe-width 20)))
@end lisp


@item
@code{(STRING . BOOLEAN)}

In this case STRING (usually an ellipsis) is shown at the end
of the heading of every collapsed section.  Expanded sections
get no indicator.  The cdr controls whether the appearance of
these ellipsis take section highlighting into account.  Doing
so might potentially have an impact on performance, while not
doing so is kinda ugly.
@end itemize
@end defopt

@node Section Hooks
@subsection Section Hooks

Which sections are inserted into certain buffers is controlled with
hooks.  This includes the status and the refs buffers.  For other
buffers, e.g. log and diff buffers, this is not possible.  The command
@code{magit-describe-section} can be used to see which hook (if any) was
responsible for inserting the section at point.

For buffers whose sections can be customized by the user, a hook
variable called @code{magit-TYPE-sections-hook} exists.  This hook should be
changed using @code{magit-add-section-hook}.  Avoid using @code{add-hooks} or the
Custom interface.

The various available section hook variables are described later in
this manual along with the appropriate "section inserter functions".

@defun magit-add-section-hook hook function &optional at append local

Add the function FUNCTION to the value of section hook HOOK@.

Add FUNCTION at the beginning of the hook list unless optional
APPEND is non-nil, in which case FUNCTION is added at the end.  If
FUNCTION already is a member then move it to the new location.

If optional AT is non-nil and a member of the hook list, then add
FUNCTION next to that instead.  Add before or after AT, or replace
AT with FUNCTION depending on APPEND@.  If APPEND is the symbol
@code{replace}, then replace AT with FUNCTION@.  For any other non-nil value
place FUNCTION right after AT@.  If nil, then place FUNCTION right
before AT@.  If FUNCTION already is a member of the list but AT is
not, then leave FUNCTION where ever it already is.

If optional LOCAL is non-nil, then modify the hook's buffer-local
value rather than its global value.  This makes the hook local by
copying the default value.  That copy is then modified.

HOOK should be a symbol.  If HOOK is void, it is first set to nil.
HOOK's value must not be a single hook function.  FUNCTION should
be a function that takes no arguments and inserts one or multiple
sections at point, moving point forward.  FUNCTION may choose not
to insert its section(s), when doing so would not make sense.  It
should not be abused for other side-effects.
@end defun

To remove a function from a section hook, use @code{remove-hook}.

@node Section Types and Values
@subsection Section Types and Values

Each section has a type, for example @code{hunk}, @code{file}, and @code{commit}.
Instances of certain section types also have a value.  The value of a
section of type @code{file}, for example, is a file name.

Users usually do not have to worry about a section's type and value,
but knowing them can be handy at times.

@table @asis
@kindex M-x magit-describe-section-briefly
@cindex magit-describe-section-briefly
@item @kbd{M-x magit-describe-section-briefly} @tie{}@tie{}@tie{}@tie{}(@code{magit-describe-section-briefly})

Show information about the section at point in the echo area, as
"#<magit-section VALUE [TYPE PARENT-TYPE@dots{}] BEGINNING-END>".
@end table

Many commands behave differently depending on the type of the section
at point and/or somehow consume the value of that section.  But that
is only one of the reasons why the same key may do something different,
depending on what section is current.

Additionally for each section type a keymap @strong{might} be defined, named
@code{magit-TYPE-section-map}.  That keymap is used as text property keymap
of all text belonging to any section of the respective type.  If such
a map does not exist for a certain type, then you can define it
yourself, and it will automatically be used.

@node Section Options
@subsection Section Options

This section describes options that have an effect on more than just a
certain type of sections.  As you can see there are not many of those.

@defopt magit-section-show-child-count

Whether to append the number of children to section headings.  This
only affects sections that could benefit from this information.
@end defopt

@node Transient Commands
@section Transient Commands

Many Magit commands are implemented as @strong{transient} commands.  First the
user invokes a @strong{prefix} command, which causes its @strong{infix} arguments and
@strong{suffix} commands to be displayed in the echo area.  The user then
optionally sets some infix arguments and finally invokes one of the
suffix commands.

This is implemented in the library @code{transient}.  Earlier Magit releases
used the package @code{magit-popup} and even earlier versions library
@code{magit-key-mode}.

Transient is documented in @ref{Top,,,transient,}.

@table @asis
@kindex C-c C-c
@cindex magit-dispatch
@item @kbd{C-c C-c} @tie{}@tie{}@tie{}@tie{}(@code{magit-dispatch})

This transient prefix command binds most of Magit's other prefix
commands as suffix commands and displays them in a temporary buffer
until one of them is invoked.  Invoking such a sub-prefix causes the
suffixes of that command to be bound and displayed instead of those
of @code{magit-dispatch}.
@end table

This command is also, or especially, useful outside Magit buffers, so
you should setup a global binding:

@lisp
(global-set-key (kbd "C-x M-g") 'magit-dispatch)
@end lisp

@node Transient Arguments and Buffer Variables
@section Transient Arguments and Buffer Variables

The infix arguments of many of Magit's transient prefix commands cease
to have an effect once the @code{git} command that is called with those
arguments has returned.  Commands that create a commit are a good
example for this.  If the user changes the arguments, then that only
affects the next invocation of a suffix command.  If the same
transient prefix command is later invoked again, then the arguments
are initially reset to the default value.  This default value can be
set for the current Emacs session or saved permanently, see
@ref{Saving Values,,,transient,}.  It is also possible to cycle through
previously used sets of arguments using @code{M-p} and @code{M-n}, see
@ref{Using History,,,transient,}.

However the infix arguments of many other transient commands continue
to have an effect even after the @code{git} command that was called with
those arguments has returned.  The most important commands like this
are those that display a diff or log in a dedicated buffer.  Their
arguments obviously continue to have an effect for as long as the
respective diff or log is being displayed.  Furthermore the used
arguments are stored in buffer-local variables for future reference.

For commands in the second group it isn't always desirable to reset
their arguments to the global value when the transient prefix command
is invoked again.

As mentioned above, it is possible to cycle through previously used
sets of arguments while a transient popup is visible.  That means that
we could always reset the infix arguments to the default because the
set of arguments that is active in the existing buffer is only a few
@code{M-p} away.  Magit can be configured to behave like that, but because I
expect that most users would not find that very convenient, it is not
the default.

Also note that it is possible to change the diff and log arguments
used in the current buffer (including the status buffer, which
contains both diff and log sections) using the respective "refresh"
transient prefix commands on @code{D} and @code{L}.  (@code{d} and @code{l} on the other hand are
intended to change @strong{what} diff or log is being displayed.  It is
possible to also change @strong{how} the diff or log is being displayed at the
same time, but if you only want to do the latter, then you should use
the refresh variants.)  Because these secondary diff and log transient
prefixes are about @strong{changing} the arguments used in the current buffer,
they @strong{always} start out with the set of arguments that are currently in
effect in that buffer.

Some commands are usually invoked directly even though they can also
be invoked as the suffix of a transient prefix command.  Most
prominently @code{magit-show-commit} is usually invoked by typing @code{RET} while
point is on a commit in a log, but it can also be invoked from the
@code{magit-diff} transient prefix.

When such a command is invoked directly, then it is important to reuse
the arguments as specified by the respective buffer-local values,
instead of using the default arguments.  Imagine you press @code{RET} in a
log to display the commit at point in a different buffer and then use
@code{D} to change how the diff is displayed in that buffer.  And then you
press @code{RET} on another commit to show that instead and the diff
arguments are reset to the default.  Not cool; so Magit does not do
that by default.

@defopt magit-prefix-use-buffer-arguments

This option controls whether the infix arguments initially shown in
certain transient prefix commands are based on the arguments that
are currently in effect in the buffer that their suffixes update.

The @code{magit-diff} and @code{magit-log} transient prefix commands are affected
by this option.
@end defopt

@defopt magit-direct-use-buffer-arguments

This option controls whether certain commands, when invoked directly
(i.e. not as the suffix of a transient prefix command), use the
arguments that are currently active in the buffer that they are
about to update.  The alternative is to use the default value for
these arguments, which might change the arguments that are used in
the buffer.
@end defopt

@noindent
Valid values for both of the above options are:

@itemize
@item
@code{always}: Always use the set of arguments that is currently active
in the respective buffer, provided that buffer exists of course.

@item
@code{selected} or @code{t}: Use the set of arguments from the respective
buffer, but only if it is displayed in a window of the current
frame.  This is the default for both variables.

@item
@code{current}: Use the set of arguments from the respective buffer, but
only if it is the current buffer.

@item
@code{never}: Never use the set of arguments from the respective buffer.
@end itemize

@noindent
I am afraid it gets more complicated still:

@itemize
@item
The global diff and log arguments are set for each support mode
individually.  The diff arguments for example have different values
in @code{magit-diff-mode}, @code{magit-revision-mode}, @code{magit-merge-preview-mode}
and @code{magit-status-mode} buffers.  Setting or saving the value for one
mode does not change the value for other modes.  The history however
is shared.


@item
When @code{magit-show-commit} is invoked directly from a log buffer, then
the file filter is picked up from that buffer, not from the revision
buffer and or the mode's global diff arguments.


@item
Even though they are suffixes of the diff prefix @code{magit-show-commit}
and @code{magit-stash-show} do not use the diff buffer used by the diff
commands, instead they use the dedicated revision and stash buffers.

At the time you invoke the diff prefix it is unknown to Magit which
of the suffix commands you are going to invoke.  While not certain,
more often than not users invoke one of the commands that use the
diff buffer, so the initial infix arguments are those used in that
buffer.  However if you invoke one of these commands directly, then
Magit knows that it should use the arguments from the revision resp.
stash buffer.


@item
The log prefix also features reflog commands, but these commands do
not use the log arguments.


@item
If @code{magit-show-refs} is invoked from a @code{magit-refs-mode} buffer, then it
acts as a refresh prefix and therefore unconditionally uses the
buffer's arguments as initial arguments. If it is invoked elsewhere
with a prefix argument, then it acts as regular prefix and therefore
respects @code{magit-prefix-use-buffer-arguments}.  If it is invoked
elsewhere without a prefix argument, then it acts as a direct
command and therefore respects @code{magit-direct-use-buffer-arguments}.
@end itemize

@node Completion Confirmation and the Selection
@section Completion, Confirmation and the Selection

@menu
* Action Confirmation::
* Completion and Confirmation::
* The Selection::
* The hunk-internal region::
* Support for Completion Frameworks::
* Additional Completion Options::
@end menu

@node Action Confirmation
@subsection Action Confirmation

By default many actions that could potentially lead to data loss have
to be confirmed.  This includes many very common actions, so this can
quickly become annoying.  Many of these actions can be undone and if
you have thought about how to undo certain mistakes, then it should
be safe to disable confirmation for the respective actions.

The option @code{magit-no-confirm} can be used to tell Magit to perform
certain actions without the user having to confirm them.  Note that
while this option can only be used to disable confirmation for a
specific set of actions, the next section explains another way of
telling Magit to ask fewer questions.

@defopt magit-no-confirm

The value of this option is a list of symbols, representing actions
that do not have to be confirmed by the user before being carried
out.

By default many potentially dangerous commands ask the user for
confirmation.  Each of the below symbols stands for an action which,
when invoked unintentionally or without being fully aware of the
consequences, could lead to tears.  In many cases there are several
commands that perform variations of a certain action, so we don't
use the command names but more generic symbols.

@itemize
@item
Applying changes:

@itemize
@item
@code{discard} Discarding one or more changes (i.e. hunks or the
complete diff for a file) loses that change, obviously.


@item
@code{reverse} Reverting one or more changes can usually be undone by
reverting the reversion.


@item
@code{stage-all-changes}, @code{unstage-all-changes} When there are both
staged and unstaged changes, then un-/staging everything would
destroy that distinction.  Of course that also applies when
un-/staging a single change, but then less is lost and one does
that so often that having to confirm every time would be
unacceptable.
@end itemize


@item
Files:

@itemize
@item
@code{delete} When a file that isn't yet tracked by Git is deleted,
then it is completely lost, not just the last changes.  Very
dangerous.


@item
@code{trash} Instead of deleting a file it can also be move to the
system trash.  Obviously much less dangerous than deleting it.

Also see option @code{magit-delete-by-moving-to-trash}.


@item
@code{resurrect} A deleted file can easily be resurrected by "deleting"
the deletion, which is done using the same command that was used
to delete the same file in the first place.


@item
@code{untrack} Untracking a file can be undone by tracking it again.


@item
@code{rename} Renaming a file can easily be undone.
@end itemize


@item
Sequences:

@itemize
@item
@code{reset-bisect} Aborting (known to Git as "resetting") a bisect
operation loses all information collected so far.


@item
@code{abort-rebase} Aborting a rebase throws away all already modified
commits, but it's possible to restore those from the reflog.


@item
@code{abort-merge} Aborting a merge throws away all conflict
resolutions which have already been carried out by the user.


@item
@code{merge-dirty} Merging with a dirty worktree can make it hard to go
back to the state before the merge was initiated.
@end itemize


@item
References:

@itemize
@item
@code{delete-unmerged-branch} Once a branch has been deleted, it can
only be restored using low-level recovery tools provided by Git.
And even then the reflog is gone.  The user always has to
confirm the deletion of a branch by accepting the default choice
(or selecting another branch), but when a branch has not been
merged yet, also make sure the user is aware of that.


@item
@code{delete-pr-remote} When deleting a branch that was created from a
pull-request and if no other branches still exist on that
remote, then `magit-branch-delete' offers to delete the remote
as well.  This should be safe because it only happens if no
other refs exist in the remotes namespace, and you can recreate
the remote if necessary.


@item
@code{drop-stashes} Dropping a stash is dangerous because Git stores
stashes in the reflog.  Once a stash is removed, there is no
going back without using low-level recovery tools provided by
Git.  When a single stash is dropped, then the user always has
to confirm by accepting the default (or selecting another).
This action only concerns the deletion of multiple stashes at
once.
@end itemize


@item
Edit published history:

Without adding these symbols here, you will be warned before
editing commits that have already been pushed to one of the
branches listed in @code{magit-published-branches}.

@itemize
@item
@code{amend-published} Affects most commands that amend to "HEAD".


@item
@code{rebase-published} Affects commands that perform interactive
rebases.  This includes commands from the commit transient that
modify a commit other than "HEAD", namely the various fixup and
squash variants.


@item
@code{edit-published} Affects the commands @code{magit-edit-line-commit} and
@code{magit-diff-edit-hunk-commit}.  These two commands make it quite
easy to accidentally edit a published commit, so you should
think twice before configuring them not to ask for confirmation.
@end itemize

To disable confirmation completely, add all three symbols here or
set @code{magit-published-branches} to @code{nil}.


@item
Various:

@itemize
@item
@code{kill-process} There seldom is a reason to kill a process.
@end itemize


@item
Global settings:

Instead of adding all of the above symbols to the value of this
option, you can also set it to the atom `t', which has the same
effect as adding all of the above symbols.  Doing that most
certainly is a bad idea, especially because other symbols might be
added in the future.  So even if you don't want to be asked for
confirmation for any of these actions, you are still better of
adding all of the respective symbols individually.

When @code{magit-wip-before-change-mode} is enabled, then the following
actions can be undone fairly easily: @code{discard}, @code{reverse},
@code{stage-all-changes}, and @code{unstage-all-changes}.  If and only if
this mode is enabled, then @code{safe-with-wip} has the same effect as
adding all of these symbols individually.
@end itemize
@end defopt

@node Completion and Confirmation
@subsection Completion and Confirmation

Many Magit commands ask the user to select from a list of possible
things to act on, while offering the most likely choice as the
default.  For many of these commands the default is the thing at
point, provided that it actually is a valid thing to act on.  For
many commands that act on a branch, the current branch serves as
the default if there is no branch at point.

These commands combine asking for confirmation and asking for a target
to act on into a single action.  The user can confirm the default
target using @code{RET} or abort using @code{C-g}.  This is similar to a @code{y-or-n-p}
prompt, but the keys to confirm or abort differ.

At the same time the user is also given the opportunity to select
another target, which is useful because for some commands and/or in
some situations you might want to select the action before selecting
the target by moving to it.

However you might find that for some commands you always want to use
the default target, if any, or even that you want the command to act
on the default without requiring any confirmation at all.  The option
@code{magit-dwim-selection} can be used to configure certain commands to that
effect.

Note that when the region is active then many commands act on the
things that are selected using a mechanism based on the region, in
many cases after asking for confirmation.  This region-based mechanism
is called the "selection" and is described in detail in the next
section.  When a selection exists that is valid for the invoked
command, then that command never offers to act on something else, and
whether it asks for confirmation is not controlled by this option.

Also note that Magit asks for confirmation of certain actions that are
not coupled with completion (or the selection).  Such dialogs are also
not affected by this option and are described in the previous section.

@defopt magit-dwim-selection
@end defopt

This option can be used to tell certain commands to use the thing
at point instead of asking the user to select a candidate to act
on, with or without confirmation.

The value has the form @code{((COMMAND nil|PROMPT DEFAULT)...)}.

@itemize
@item
COMMAND is the command that should not prompt for a choice.
To have an effect, the command has to use the function
@code{magit-completing-read} or a utility function which in turn uses
that function.


@item
If the command uses @code{magit-completing-read} multiple times, then
PROMPT can be used to only affect one of these uses.  PROMPT, if
non-nil, is a regular expression that is used to match against
the PROMPT argument passed to @code{magit-completing-read}.


@item
DEFAULT specifies how to use the default.  If it is @code{t}, then
the DEFAULT argument passed to @code{magit-completing-read} is used
without confirmation.  If it is @code{ask}, then the user is given
a chance to abort.  DEFAULT can also be @code{nil}, in which case the
entry has no effect.
@end itemize

@node The Selection
@subsection The Selection

If the region is active, then many Magit commands act on the things
that are selected using a mechanism based on the region instead of one
single thing.  When the region is not active, then these commands act
on the thing at point or read a single thing to act on.  This is
described in the previous section — this section only covers how
multiple things are selected, how that is visualized, and how certain
commands behave when that is the case.

Magit's mechanism for selecting multiple things, or rather sections
that represent these things, is based on the Emacs region, but the
area that Magit considers to be selected is typically larger than the
region and additional restrictions apply.

Magit makes a distinction between a region that qualifies as forming a
valid Magit selection and a region that does not.  If the region does
not qualify, then it is displayed as it is in other Emacs buffers.  If
the region does qualify as a Magit selection, then the selection is
always visualized, while the region itself is only visualized if it
begins and ends on the same line.

For a region to qualify as a Magit selection, it must begin in the
heading of one section and end in the heading of a sibling section.
Note that if the end of the region is at the very beginning of section
heading (i.e. at the very beginning of a line) then that section is
considered to be @strong{inside} the selection.

This is not consistent with how the region is normally treated in
Emacs — if the region ends at the beginning of a line, then that line
is outside the region.  Due to how Magit visualizes the selection, it
should be obvious that this difference exists.

Not every command acts on every valid selection.  Some commands do not
even consider the location of point, others may act on the section at
point but not support acting on the selection, and even commands that
do support the selection of course only do so if it selects things
that they can act on.

This is the main reason why the selection must include the section at
point.  Even if a selection exists, the invoked command may disregard
it, in which case it may act on the current section only.  It is much
safer to only act on the current section but not the other selected
sections than it is to act on the current section @strong{instead} of the
selected sections.  The latter would be much more surprising and if
the current section always is part of the selection, then that cannot
happen.

@defvar magit-keep-region-overlay

This variable controls whether the region is visualized as usual
even when a valid Magit selection or a hunk-internal region exists.
See the doc-string for more information.
@end defvar

@node The hunk-internal region
@subsection The hunk-internal region

Somewhat related to the Magit selection described in the previous
section is the hunk-internal region.

Like the selection, the hunk-internal region is based on the Emacs
region but causes that region to not be visualized as it would in
other Emacs buffers, and includes the line on which the region ends
even if it ends at the very beginning of that line.

Unlike the selection, which is based on a region that must begin in
the heading of one section and ends in the section of a sibling
section, the hunk-internal region must begin inside the @strong{body} of a
hunk section and end in the body of the @strong{same} section.

The hunk-internal region is honored by "apply" commands, which can,
among other targets, act on a hunk.  If the hunk-internal region is
active, then such commands act only on the marked part of the hunk
instead of on the complete hunk.

@node Support for Completion Frameworks
@subsection Support for Completion Frameworks

The built-in option @code{completing-read-function} specifies the low-level
function used by @code{completing-read} to ask a user to select from a list
of choices.  Its default value is @code{completing-read-default}.
Alternative completion frameworks typically activate themselves by
substituting their own implementation.

Mostly for historic reasons Magit provides a similar option named
@code{magit-completing-read-function}, which only controls the low-level
function used by @code{magit-completing-read}.  This option also makes it
possible to use a different completing mechanism for Magit than for
the rest of Emacs, but doing that is not recommend.

You most likely don't have to customize the magit-specific option to
use an alternative completion framework.  For example, if you enable
@code{ivy-mode}, then Magit will respect that, and if you enable @code{helm-mode},
then you are done too.

However if you want to use Ido, then @code{ido-mode} won't do the trick.  You
will also have to install the @code{ido-completing-read+} package and use
@code{magit-ido-completing-read} as @code{magit-completing-read-function}.

@defopt magit-completing-read-function

The value of this variable is the low-level function used to perform
completion by code that uses @code{magit-completing-read} (as opposed to
the built-in @code{completing-read}).

The default value, @code{magit-builtin-completing-read}, is suitable for
the standard completion mechanism, @code{ivy-mode}, and @code{helm-mode} at least.

The built-in @code{completing-read} and @code{completing-read-default} are @strong{not}
suitable to be used here.  @code{magit-builtin-completing-read} performs
some additional work, and any function used in its place has to do
the same.
@end defopt

@defun magit-builtin-completing-read prompt choices &optional predicate require-match initial-input hist def

This function performs completion using the built-in @code{completing-read}
and does some additional magit-specific work.
@end defun

@defun magit-ido-completing-read prompt choices &optional predicate require-match initial-input hist def

This function performs completion using @code{ido-completing-read+} from the
package by the same name (which you have to explicitly install) and
does some additional magit-specific work.

We have to use @code{ido-completing-read+} instead of the
@code{ido-completing-read} that comes with Ido itself, because the latter,
while intended as a drop-in replacement, cannot serve that purpose
because it violates too many of the implicit conventions.
@end defun

@defun magit-completing-read prompt choices &optional predicate require-match initial-input hist def fallback

This is the function that Magit commands use when they need the user
to select a single thing to act on.  The arguments have the same
meaning as for @code{completing-read}, except for FALLBACK, which is unique
to this function and is described below.

Instead of asking the user to choose from a list of possible
candidates, this function may just return the default specified by
DEF, with or without requiring user confirmation.  Whether that is
the case depends on PROMPT, @code{this-command} and @code{magit-dwim-selection}.
See the documentation of the latter for more information.

If it does read a value in the minibuffer, then this function acts
similar to @code{completing-read}, except for the following:

@itemize
@item
COLLECTION must be a list of choices.  A function is not
supported.


@item
If REQUIRE-MATCH is @code{nil} and the user exits without a choice, then
@code{nil} is returned instead of an empty string.


@item
If REQUIRE-MATCH is non-nil and the users exits without a choice,
an user-error is raised.


@item
FALLBACK specifies a secondary default that is only used if the
primary default DEF is @code{nil}.  The secondary default is not subject
to @code{magit-dwim-selection} — if DEF is @code{nil} but FALLBACK is not, then
this function always asks the user to choose a candidate, just as
if both defaults were @code{nil}.


@item
": " is appended to PROMPT@.


@item
PROMPT is modified to end with \" (default DEF|FALLBACK): \"
provided that DEF or FALLBACK is non-nil, that neither @code{ivy-mode}
nor @code{helm-mode} is enabled, and that
@code{magit-completing-read-function} is set to its default value of
@code{magit-builtin-completing-read}.
@end itemize
@end defun

@node Additional Completion Options
@subsection Additional Completion Options

@defopt magit-list-refs-sortby

For many commands that read a ref or refs from the user, the value
of this option can be used to control the order of the refs.  Valid
values include any key accepted by the @code{--sort} flag of @code{git
  for-each-ref}.  By default, refs are sorted alphabetically by their
full name (e.g., "refs/heads/master").
@end defopt

@node Running Git
@section Running Git

@menu
* Viewing Git Output::
* Git Process Status::
* Running Git Manually::
* Git Executable::
* Global Git Arguments::
@end menu

@node Viewing Git Output
@subsection Viewing Git Output

Magit runs Git either for side-effects (e.g. when pushing) or to get
some value (e.g. the name of the current branch).

When Git is run for side-effects, the process output is logged in a
per-repository log buffer, which can be consulted using the
@code{magit-process} command when things don't go as expected.

The output/errors for up to `magit-process-log-max' Git commands are
retained.

@table @asis
@kindex $
@cindex magit-process
@item @kbd{$} @tie{}@tie{}@tie{}@tie{}(@code{magit-process})

This commands displays the process buffer for the current
repository.
@end table

Inside that buffer, the usual key bindings for navigating and showing
sections are available.  There is one additional command.

@table @asis
@kindex k
@cindex magit-process-kill
@item @kbd{k} @tie{}@tie{}@tie{}@tie{}(@code{magit-process-kill})

This command kills the process represented by the section at point.

@end table

@defopt magit-git-debug

When this is non-nil then the output of all calls to git are logged
in the process buffer.  This is useful when debugging, otherwise it
just negatively affects performance.
@end defopt

@node Git Process Status
@subsection Git Process Status

When a Git process is running for side-effects, Magit displays an
indicator in the mode line, using the @code{magit-mode-line-process} face.

If the Git process exits successfully, the process indicator is
removed from the mode line immediately.

In the case of a Git error, the process indicator is not removed, but
is instead highlighted with the @code{magit-mode-line-process-error} face,
and the error details from the process buffer are provided as a
tooltip for mouse users.  This error indicator persists in the mode
line until the next magit buffer refresh.

If you do not wish process errors to be indicated in the mode line,
customize the @code{magit-process-display-mode-line-error} user option.

Process errors are additionally indicated at the top of the status
buffer.

@node Running Git Manually
@subsection Running Git Manually

While Magit provides many Emacs commands to interact with Git, it does
not cover everything.  In those cases your existing Git knowledge will
come in handy.  Magit provides some commands for running arbitrary Git
commands by typing them into the minibuffer, instead of having to
switch to a shell.

@table @asis
@kindex !
@cindex magit-run
@item @kbd{!} @tie{}@tie{}@tie{}@tie{}(@code{magit-run})

This transient prefix command binds the following suffix commands
and displays them in a temporary buffer until a suffix is invoked.

@kindex ! !
@cindex magit-git-command-topdir
@item @kbd{! !} @tie{}@tie{}@tie{}@tie{}(@code{magit-git-command-topdir})

This command reads a command from the user and executes it in the
top-level directory of the current working tree.

The string "git " is used as initial input when prompting the user
for the command.  It can be removed to run another command.

@kindex ! p
@cindex magit-git-command
@item @kbd{! p} @tie{}@tie{}@tie{}@tie{}(@code{magit-git-command})

This command reads a command from the user and executes it in
@code{default-directory}.  With a prefix argument the command is executed
in the top-level directory of the current working tree instead.

The string "git " is used as initial input when prompting the user
for the command.  It can be removed to run another command.

@kindex ! s
@cindex magit-shell-command-topdir
@item @kbd{! s} @tie{}@tie{}@tie{}@tie{}(@code{magit-shell-command-topdir})

This command reads a command from the user and executes it in the
top-level directory of the current working tree.

@kindex ! S
@cindex magit-shell-command
@item @kbd{! S} @tie{}@tie{}@tie{}@tie{}(@code{magit-shell-command})

This command reads a command from the user and executes it in
@code{default-directory}.  With a prefix argument the command is executed
in the top-level directory of the current working tree instead.

@end table

@defopt magit-shell-command-verbose-prompt

Whether the prompt, used by the above commands when reading a
shell command, shows the directory in which it will be run.
@end defopt

These suffix commands start external gui tools.

@table @asis
@kindex ! k
@cindex magit-run-gitk
@item @kbd{! k} @tie{}@tie{}@tie{}@tie{}(@code{magit-run-gitk})

This command runs @code{gitk} in the current repository.

@kindex ! a
@cindex magit-run-gitk-all
@item @kbd{! a} @tie{}@tie{}@tie{}@tie{}(@code{magit-run-gitk-all})

This command runs @code{gitk --all} in the current repository.

@kindex ! b
@cindex magit-run-gitk-branches
@item @kbd{! b} @tie{}@tie{}@tie{}@tie{}(@code{magit-run-gitk-branches})

This command runs @code{gitk --branches} in the current repository.

@kindex ! g
@cindex magit-run-git-gui
@item @kbd{! g} @tie{}@tie{}@tie{}@tie{}(@code{magit-run-git-gui})

This command runs @code{git gui} in the current repository.
@end table

@node Git Executable
@subsection Git Executable

Except on MS Windows, Magit defaults to running Git without specifying
the path to the git executable.  Instead the first executable found by
Emacs on @code{exec-path} is used (whose value in turn is set based on the
value of the environment variable @code{$PATH} when Emacs was started).

This has the advantage that it continues to work even when using Tramp
to connect to a remote machine on which the executable is found in a
different place.  The downside is that if you have multiple versions
of Git installed, then you might end up using another version than the
one you think you are using.

@table @asis
@kindex M-x magit-version
@cindex magit-version
@item @kbd{M-x magit-version} @tie{}@tie{}@tie{}@tie{}(@code{magit-version})

This command shows the currently used versions of Magit, Git, and
Emacs in the echo area.  Non-interactively this just returns the
Magit version.
@end table

When the @code{system-type} is @code{windows-nt}, then @code{magit-git-executable} is set
to an absolute path when Magit is first loaded.  This is necessary
because Git on that platform comes with several wrapper scripts for
the actual git binary, which are also placed on @code{$PATH}, and using one
of these wrappers instead of the binary would degrade performance
horribly.

If Magit doesn't find the correct executable then you @strong{can} work
around that by setting @code{magit-git-executable} to an absolute path.
But note that doing so is a kludge.  It is better to make sure the
order in the environment variable @code{$PATH} is correct, and that Emacs
is started with that environment in effect.  The command
@code{magit-debug-git-executable} can be useful to find out where Emacs is
searching for git.  If you have to connect from Windows to a
non-Windows machine, then you must change the value to "git".

@defopt magit-git-executable

The git executable used by Magit, either the full path to the
executable or the string "git" to let Emacs find the executable
itself, using the standard mechanism for doing such things.
@end defopt

@table @asis
@kindex M-x magit-debug-git-executable
@cindex magit-debug-git-executable
@item @kbd{M-x magit-debug-git-executable} @tie{}@tie{}@tie{}@tie{}(@code{magit-debug-git-executable})

Display a buffer with information about @code{magit-git-executable}.
@end table

@node Global Git Arguments
@subsection Global Git Arguments

@defopt magit-git-global-arguments

The arguments set here are used every time the git executable is run
as a subprocess.  They are placed right after the executable itself
and before the git command - as in @code{git HERE... COMMAND REST}.  For
valid arguments see 
@ifinfo
@ref{git,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git">git(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git(1) manpage.
@end iftex

Be careful what you add here, especially if you are using Tramp to
connect to servers with ancient Git versions.  Never remove anything
that is part of the default value, unless you really know what you
are doing.  And think very hard before adding something; it will be
used every time Magit runs Git for any purpose.
@end defopt

@node Inspecting
@chapter Inspecting

The functionality provided by Magit can be roughly divided into three
groups: inspecting existing data, manipulating existing data or adding
new data, and transferring data.  Of course that is a rather crude
distinction that often falls short, but it's more useful than no
distinction at all.  This section is concerned with inspecting data,
the next two with manipulating and transferring it.  Then follows a
section about miscellaneous functionality, which cannot easily be fit
into this distinction.

Of course other distinctions make sense too, e.g. Git's distinction
between porcelain and plumbing commands, which for the most part is
equivalent to Emacs' distinction between interactive commands and
non-interactive functions.  All of the sections mentioned before are
mainly concerned with the porcelain -- Magit's plumbing layer is
described later.

@menu
* Status Buffer::
* Repository List::
* Logging::
* Diffing::
* Ediffing::
* References Buffer::
* Bisecting::
* Visiting Files and Blobs::
* Blaming::
@end menu

@node Status Buffer
@section Status Buffer

While other Magit buffers contain e.g. one particular diff or one
particular log, the status buffer contains the diffs for staged and
unstaged changes, logs for unpushed and unpulled commits, lists of
stashes and untracked files, and information related to the current
branch.

During certain incomplete operations -- for example when a merge
resulted in a conflict -- additional information is displayed that
helps proceeding with or aborting the operation.

The command @code{magit-status} displays the status buffer belonging to the
current repository in another window.  This command is used so often
that it should be bound globally.  We recommend using @code{C-x g}:

@lisp
(global-set-key (kbd "C-x g") 'magit-status)
@end lisp

@table @asis
@kindex C-x g
@cindex magit-status
@item @kbd{C-x g} @tie{}@tie{}@tie{}@tie{}(@code{magit-status})

When invoked from within an existing Git repository, then this
command shows the status of that repository in a buffer.

If the current directory isn't located within a Git repository, then
this command prompts for an existing repository or an arbitrary
directory, depending on the option @code{magit-repository-directories}, and
the status for the selected repository is shown instead.

@itemize
@item
If that option specifies any existing repositories, then the user
is asked to select one of them.


@item
Otherwise the user is asked to select an arbitrary directory using
regular file-name completion.  If the selected directory is the
top-level directory of an existing working tree, then the status
buffer for that is shown.


@item
Otherwise the user is offered to initialize the selected directory
as a new repository.  After creating the repository its status
buffer is shown.
@end itemize

These fallback behaviors can also be forced using one or more
prefix arguments:

@itemize
@item
With two prefix arguments (or more precisely a numeric prefix
value of 16 or greater) an arbitrary directory is read, which is
then acted on as described above.  The same could be accomplished
using the command @code{magit-init}.


@item
With a single prefix argument an existing repository is read from
the user, or if no repository can be found based on the value of
@code{magit-repository-directories}, then the behavior is the same as with
two prefix arguments.
@end itemize

@end table

@defopt magit-repository-directories

List of directories that are Git repositories or contain Git
repositories.

Each element has the form @code{(DIRECTORY . DEPTH)}.  DIRECTORY has to be
a directory or a directory file-name, a string.  DEPTH, an integer,
specifies the maximum depth to look for Git repositories.  If it is
0, then only add DIRECTORY itself.

This option controls which repositories are being listed by
@code{magit-list-repositories}.  It also affects @code{magit-status} (which see)
in potentially surprising ways (see above).
@end defopt

@cindex ido-enter-magit-status
@deffn Command ido-enter-magit-status

From an Ido prompt used to open a file, instead drop into
@code{magit-status}.  This is similar to @code{ido-magic-delete-char}, which,
despite its name, usually causes a Dired buffer to be created.

To make this command available, use something like:

@lisp
(add-hook 'ido-setup-hook
          (lambda ()
            (define-key ido-completion-map
              (kbd \"C-x g\") 'ido-enter-magit-status)))
@end lisp

Starting with Emacs 25.1 the Ido keymaps are defined just once
instead of every time Ido is invoked, so now you can modify it
like pretty much every other keymap:

@lisp
(define-key ido-common-completion-map
  (kbd \"C-x g\") 'ido-enter-magit-status)
@end lisp
@end deffn

@menu
* Status Sections::
* Status Header Sections::
* Status Module Sections::
* Status Options::
@end menu

@node Status Sections
@subsection Status Sections

The contents of status buffers is controlled using the hook
@code{magit-status-sections-hook}.  See @ref{Section Hooks} to learn about such
hooks and how to customize them.

@defopt magit-status-sections-hook

Hook run to insert sections into a status buffer.
@end defopt

The first function on that hook by default is
@code{magit-insert-status-headers}; it is described in the next section.
By default the following functions are also members of that hook:

@defun magit-insert-merge-log

Insert section for the on-going merge.  Display the heads that are
being merged.  If no merge is in progress, do nothing.
@end defun

@defun magit-insert-rebase-sequence

Insert section for the on-going rebase sequence.
If no such sequence is in progress, do nothing.
@end defun

@defun magit-insert-am-sequence

Insert section for the on-going patch applying sequence.
If no such sequence is in progress, do nothing.
@end defun

@defun magit-insert-sequencer-sequence

Insert section for the on-going cherry-pick or revert sequence.
If no such sequence is in progress, do nothing.
@end defun

@defun magit-insert-bisect-output

While bisecting, insert section with output from @code{git bisect}.
@end defun

@defun magit-insert-bisect-rest

While bisecting, insert section visualizing the bisect state.
@end defun

@defun magit-insert-bisect-log

While bisecting, insert section logging bisect progress.
@end defun

@defun magit-insert-untracked-files

Maybe insert a list or tree of untracked files.

Do so depending on the value of @code{status.showUntrackedFiles}.  Note
that even if the value is @code{all}, Magit still initially only shows
directories.  But the directory sections can then be expanded using
@code{TAB}.
@end defun

@defun magit-insert-unstaged-changes

Insert section showing unstaged changes.
@end defun

@defun magit-insert-staged-changes

Insert section showing staged changes.
@end defun

@defun magit-insert-stashes &optional ref heading

Insert the @code{stashes} section showing reflog for "refs/stash".
If optional REF is non-nil show reflog for that instead.
If optional HEADING is non-nil use that as section heading
instead of "Stashes:".
@end defun

@defun magit-insert-unpulled-from-upstream

Insert section showing commits that haven't been pulled from the
upstream branch yet.
@end defun

@defun magit-insert-unpulled-from-pushremote

Insert section showing commits that haven't been pulled from the
push-remote branch yet.
@end defun

@defun magit-insert-unpushed-to-upstream

Insert section showing commits that haven't been pushed to the
upstream yet.
@end defun

@defun magit-insert-unpushed-to-pushremote

Insert section showing commits that haven't been pushed to the
push-remote yet.
@end defun

The following functions can also be added to the above hook:

@defun magit-insert-tracked-files

Insert a tree of tracked files.
@end defun

@defun magit-insert-ignored-files

Insert a tree of ignored files.
Its possible to limit the logs in the current buffer to a certain
directory using @code{D = f <DIRECTORY> RET g}.  If you do that, then that
that also affects this command.

The log filter can be used to limit to multiple files.  In that case
this function only respects the first of the files and only if it is
a directory.
@end defun

@defun magit-insert-skip-worktree-files

Insert a tree of skip-worktree files.
If the first element of @code{magit-buffer-diff-files} is a
directory, then limit the list to files below that.  The value
of that variable can be set using @code{D -- DIRECTORY RET g}.
@end defun

@defun magit-insert-assumed-unchanged-files

Insert a tree of files that are assumed to be unchanged.
If the first element of @code{magit-buffer-diff-files} is a
directory, then limit the list to files below that.  The value
of that variable can be set using @code{D -- DIRECTORY RET g}.
@end defun

@defun magit-insert-unpulled-or-recent-commits

Insert section showing unpulled or recent commits.
If an upstream is configured for the current branch and it is
ahead of the current branch, then show the missing commits.
Otherwise, show the last @code{magit-log-section-commit-count}
commits.
@end defun

@defun magit-insert-recent-commits

Insert section showing the last @code{magit-log-section-commit-count}
commits.
@end defun

@defopt magit-log-section-commit-count

How many recent commits @code{magit-insert-recent-commits} and
@code{magit-insert-unpulled-or-recent-commits} (provided there are no
unpulled commits) show.
@end defopt

@defun magit-insert-unpulled-cherries

Insert section showing unpulled commits.
Like @code{magit-insert-unpulled-commits} but prefix each commit
that has not been applied yet (i.e. a commit with a patch-id
not shared with any local commit) with "+", and all others
with "-".
@end defun

@defun magit-insert-unpushed-cherries

Insert section showing unpushed commits.
Like @code{magit-insert-unpushed-commits} but prefix each commit
which has not been applied to upstream yet (i.e. a commit with
a patch-id not shared with any upstream commit) with "+" and
all others with "-".
@end defun

See @ref{References Buffer} for some more section inserters, which could be
used here.

@node Status Header Sections
@subsection Status Header Sections

The contents of status buffers is controlled using the hook
@code{magit-status-sections-hook} (see @ref{Status Sections}).

By default @code{magit-insert-status-headers} is the first member of that
hook variable.

@defun magit-insert-status-headers

Insert headers sections appropriate for @code{magit-status-mode} buffers.
The sections are inserted by running the functions on the hook
@code{magit-status-headers-hook}.
@end defun

@defopt magit-status-headers-hook

Hook run to insert headers sections into the status buffer.

This hook is run by @code{magit-insert-status-headers}, which in turn has
to be a member of @code{magit-status-sections-hook} to be used at all.
@end defopt

By default the following functions are members of the above hook:

@defun magit-insert-error-header

Insert a header line showing the message about the Git error that
just occurred.

This function is only aware of the last error that occur when Git
was run for side-effects.  If, for example, an error occurs while
generating a diff, then that error won't be inserted.  Refreshing
the status buffer causes this section to disappear again.
@end defun

@defun magit-insert-diff-filter-header

Insert a header line showing the effective diff filters.
@end defun

@defun magit-insert-head-branch-header

Insert a header line about the current branch or detached @code{HEAD}.
@end defun

@defun magit-insert-upstream-branch-header

Insert a header line about the branch that is usually pulled into
the current branch.
@end defun

@defun magit-insert-push-branch-header

Insert a header line about the branch that the current branch is
usually pushed to.
@end defun

@defun magit-insert-tags-header

Insert a header line about the current and/or next tag, along with
the number of commits between the tag and @code{HEAD}.
@end defun

The following functions can also be added to the above hook:

@defun magit-insert-repo-header

Insert a header line showing the path to the repository top-level.
@end defun

@defun magit-insert-remote-header

Insert a header line about the remote of the current branch.

If no remote is configured for the current branch, then fall back
showing the "origin" remote, or if that does not exist the first
remote in alphabetic order.
@end defun

@defun magit-insert-user-header

Insert a header line about the current user.
@end defun

@node Status Module Sections
@subsection Status Module Sections

The contents of status buffers is controlled using the hook
@code{magit-status-sections-hook} (see @ref{Status Sections}).

By default @code{magit-insert-modules} is @emph{not} a member of that hook
variable.

@defun magit-insert-modules

Insert submodule sections.

Hook @code{magit-module-sections-hook} controls which module sections are
inserted, and option @code{magit-module-sections-nested} controls whether
they are wrapped in an additional section.
@end defun

@defopt magit-module-sections-hook

Hook run by @code{magit-insert-modules}.
@end defopt

@defopt magit-module-sections-nested

This option controls whether @code{magit-insert-modules} wraps inserted
sections in an additional section.

If this is non-nil, then only a single top-level section is inserted.
If it is nil, then all sections listed in @code{magit-module-sections-hook}
become top-level sections.
@end defopt

@defun magit-insert-modules-overview

Insert sections for all submodules.  For each section insert the
path, the branch, and the output of @code{git describe --tags},
or, failing that, the abbreviated HEAD commit hash.

Press @code{RET} on such a submodule section to show its own status buffer.
Press @code{RET} on the "Modules" section to display a list of submodules
in a separate buffer.  This shows additional information not
displayed in the super-repository's status buffer.
@end defun

@defun magit-insert-modules-unpulled-from-upstream

Insert sections for modules that haven't been pulled from the
upstream yet.  These sections can be expanded to show the respective
commits.
@end defun

@defun magit-insert-modules-unpulled-from-pushremote

Insert sections for modules that haven't been pulled from the
push-remote yet.  These sections can be expanded to show the
respective commits.
@end defun

@defun magit-insert-modules-unpushed-to-upstream

Insert sections for modules that haven't been pushed to the upstream
yet.  These sections can be expanded to show the respective commits.
@end defun

@defun magit-insert-modules-unpushed-to-pushremote

Insert sections for modules that haven't been pushed to the
push-remote yet.  These sections can be expanded to show the
respective commits.
@end defun

@node Status Options
@subsection Status Options

@defopt magit-status-refresh-hook

Hook run after a status buffer has been refreshed.
@end defopt

@defopt magit-status-margin

This option specifies whether the margin is initially shown in
Magit-Status mode buffers and how it is formatted.

The value has the form @code{(INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH)}.

@itemize
@item
If INIT is non-nil, then the margin is shown initially.

@item
STYLE controls how to format the author or committer date.  It can
be one of @code{age} (to show the age of the commit), @code{age-abbreviated} (to
abbreviate the time unit to a character), or a string (suitable
for @code{format-time-string}) to show the actual date.  Option
@code{magit-log-margin-show-committer-date} controls which date is being
displayed.

@item
WIDTH controls the width of the margin.  This exists for forward
compatibility and currently the value should not be changed.

@item
AUTHOR controls whether the name of the author is also shown by
default.

@item
AUTHOR-WIDTH has to be an integer.  When the name of the author
is shown, then this specifies how much space is used to do so.
@end itemize
@end defopt

Also see the proceeding section for more options concerning status
buffers.

@node Repository List
@section Repository List

@cindex magit-list-repositories
@deffn Command magit-list-repositories

This command displays a list of repositories in a separate buffer.

The options @code{magit-repository-directories} and
@code{magit-repository-directories-depth} control which repositories are
displayed.
@end deffn

@defopt magit-repolist-columns

This option controls what columns are displayed by the command
@code{magit-list-repositories} and how they are displayed.

Each element has the form @code{(HEADER WIDTH FORMAT PROPS)}.

HEADER is the string displayed in the header.  WIDTH is the width of
the column.  FORMAT is a function that is called with one argument,
the repository identification (usually its basename), and with
@code{default-directory} bound to the toplevel of its working tree.  It
has to return a string to be inserted or nil.  PROPS is an alist
that supports the keys @code{:right-align} and @code{:pad-right}.
@end defopt

The following functions can be added to the above option:

@defun magit-repolist-column-ident

This function inserts the identification of the repository.  Usually
this is just its basename.
@end defun

@defun magit-repolist-column-path

This function inserts the absolute path of the repository.
@end defun

@defun magit-repolist-column-version

This function inserts a description of the repository's @code{HEAD} revision.
@end defun

@defun magit-repolist-column-branch

This function inserts the name of the current branch.
@end defun

@defun magit-repolist-column-upstream

This function inserts the name of the upstream branch of the current
branch.
@end defun

@defun magit-repolist-column-branches

This function inserts the number of branches.
@end defun

@defun magit-repolist-column-stashes

This function inserts the number of stashes.
@end defun

@defun magit-repolist-column-flag

This function inserts a flag as specified by
@code{magit-repolist-column-flag-alist}.

By default this indicates whether there are uncommitted changes.

@itemize
@item
@code{N} if there is at least one untracked file.

@item
@code{U} if there is at least one unstaged file.

@item
@code{S} if there is at least one staged file.
@end itemize

Only the first one of these that applies is shown.
@end defun

@defun magit-repolist-column-unpulled-from-upstream

This function inserts the number of upstream commits not in the
current branch.
@end defun

@defun magit-repolist-column-unpulled-from-pushremote

This function inserts the number of commits in the push branch but
not the current branch.
@end defun

@defun magit-repolist-column-unpushed-to-upstream

This function inserts the number of commits in the current branch
but not its upstream.
@end defun

@defun magit-repolist-column-unpushed-to-pushremote

This function inserts the number of commits in the current branch
but not its push branch.
@end defun

@node Logging
@section Logging

The status buffer contains logs for the unpushed and unpulled commits,
but that obviously isn't enough.  The transient prefix command
@code{magit-log}, on @code{l}, features several suffix commands, which show a
specific log in a separate log buffer.

Like other transient prefix commands, @code{magit-log} also features several
infix arguments that can be changed before invoking one of the suffix
commands.  However, in the case of the log transient, these arguments
may be taken from those currently in use in the current repository's
log buffer, depending on the value of @code{magit-prefix-use-buffer-arguments}
(see @ref{Transient Arguments and Buffer Variables}).

For information about the various arguments, see 
@ifinfo
@ref{git-log,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-log">git-log(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-log(1) manpage.
@end iftex

The switch @code{++order=VALUE} is converted to one of @code{--author-date-order},
@code{--date-order}, or @code{--topo-order} before being passed to @code{git log}.

The log transient also features several reflog commands.  See @ref{Reflog}.

@table @asis
@kindex l
@cindex magit-log
@item @kbd{l} @tie{}@tie{}@tie{}@tie{}(@code{magit-log})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.

@kindex l l
@cindex magit-log-current
@item @kbd{l l} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-current})

Show log for the current branch.  When @code{HEAD} is detached or with a
prefix argument, show log for one or more revs read from the
minibuffer.

@kindex l o
@cindex magit-log-other
@item @kbd{l o} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-other})

Show log for one or more revs read from the minibuffer.  The user
can input any revision or revisions separated by a space, or even
ranges, but only branches, tags, and a representation of the
commit at point are available as completion candidates.

@kindex l h
@cindex magit-log-head
@item @kbd{l h} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-head})

Show log for @code{HEAD}.

@kindex l L
@cindex magit-log-branches
@item @kbd{l L} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-branches})

Show log for all local branches and @code{HEAD}.

@kindex l b
@cindex magit-log-all-branches
@item @kbd{l b} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-all-branches})

Show log for all local and remote branches and @code{HEAD}.

@kindex l a
@cindex magit-log-all
@item @kbd{l a} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-all})

Show log for all references and @code{HEAD}.
@end table


Two additional commands that show the log for the file or blob that
is being visited in the current buffer exists, see @ref{Minor Mode for Buffers Visiting Files}.  The command @code{magit-cherry} also shows a log,
see @ref{Cherries}.

@menu
* Refreshing Logs::
* Log Buffer::
* Log Margin::
* Select from Log::
* Reflog::
* Cherries::
@end menu

@node Refreshing Logs
@subsection Refreshing Logs

The transient prefix command @code{magit-log-refresh}, on @code{L}, can be used to
change the log arguments used in the current buffer, without changing
which log is shown.  This works in dedicated log buffers, but also in
the status buffer.

@table @asis
@kindex L
@cindex magit-log-refresh
@item @kbd{L} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-refresh})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.

@kindex L g
@cindex magit-log-refresh
@item @kbd{L g} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-refresh})

This suffix command sets the local log arguments for the current
buffer.

@kindex L s
@cindex magit-log-set-default-arguments
@item @kbd{L s} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-set-default-arguments})

This suffix command sets the default log arguments for buffers of
the same type as that of the current buffer.  Other existing buffers
of the same type are not affected because their local values have
already been initialized.

@kindex L w
@cindex magit-log-save-default-arguments
@item @kbd{L w} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-save-default-arguments})

This suffix command sets the default log arguments for buffers of
the same type as that of the current buffer, and saves the value for
future sessions.  Other existing buffers of the same type are not
affected because their local values have already been initialized.

@kindex L t
@cindex magit-toggle-margin
@item @kbd{L t} @tie{}@tie{}@tie{}@tie{}(@code{magit-toggle-margin})

Show or hide the margin.
@end table

@node Log Buffer
@subsection Log Buffer

@table @asis
@kindex L
@cindex magit-log-refresh
@item @kbd{L} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-refresh})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.

See @ref{Refreshing Logs}.

@kindex q
@cindex magit-log-bury-buffer
@item @kbd{q} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-bury-buffer})

Bury the current buffer or the revision buffer in the same frame.
Like @code{magit-mode-bury-buffer} (which see) but with a negative prefix
argument instead bury the revision buffer, provided it is displayed
in the current frame.

@kindex C-c C-b
@cindex magit-go-backward
@item @kbd{C-c C-b} @tie{}@tie{}@tie{}@tie{}(@code{magit-go-backward})

Move backward in current buffer's history.

@kindex C-c C-f
@cindex magit-go-forward
@item @kbd{C-c C-f} @tie{}@tie{}@tie{}@tie{}(@code{magit-go-forward})

Move forward in current buffer's history.

@kindex C-c C-n
@cindex magit-log-move-to-parent
@item @kbd{C-c C-n} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-move-to-parent})

Move to a parent of the current commit.  By default, this is the
first parent, but a numeric prefix can be used to specify another
parent.

@kindex SPC
@cindex magit-diff-show-or-scroll-up
@item @kbd{SPC} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-show-or-scroll-up})

Update the commit or diff buffer for the thing at point.

Either show the commit or stash at point in the appropriate buffer,
or if that buffer is already being displayed in the current frame
and contains information about that commit or stash, then instead
scroll the buffer up.  If there is no commit or stash at point, then
prompt for a commit.

@kindex DEL
@cindex magit-diff-show-or-scroll-down
@item @kbd{DEL} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-show-or-scroll-down})

Update the commit or diff buffer for the thing at point.

Either show the commit or stash at point in the appropriate buffer,
or if that buffer is already being displayed in the current frame
and contains information about that commit or stash, then instead
scroll the buffer down.  If there is no commit or stash at point,
then prompt for a commit.

@kindex =
@cindex magit-log-toggle-commit-limit
@item @kbd{=} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-toggle-commit-limit})

Toggle the number of commits the current log buffer is limited to.
If the number of commits is currently limited, then remove that
limit.  Otherwise set it to 256.

@kindex +
@cindex magit-log-double-commit-limit
@item @kbd{+} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-double-commit-limit})

Double the number of commits the current log buffer is limited to.

@kindex -
@cindex magit-log-half-commit-limit
@item @kbd{-} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-half-commit-limit})

Half the number of commits the current log buffer is limited to.

@end table

@defopt magit-log-auto-more

Insert more log entries automatically when moving past the last
entry.  Only considered when moving past the last entry with
@code{magit-goto-*-section} commands.
@end defopt

@defopt magit-log-show-refname-after-summary

Whether to show the refnames after the commit summaries.  This is
useful if you use really long branch names.
@end defopt

Magit displays references in logs a bit differently from how Git does
it.

Local branches are blue and remote branches are green.  Of course that
depends on the used theme, as do the colors used for other types of
references.  The current branch has a box around it, as do remote
branches that are their respective remote's @code{HEAD} branch.

If a local branch and its push-target point at the same commit, then
their names are combined to preserve space and to make that
relationship visible.  For example:

@example
origin/feature
[green][blue-]

instead of

feature origin/feature
[blue-] [green-------]
@end example

Also note that while the transient features the @code{--show-signature}
argument, that won't actually be used when enabled, because Magit
defaults to use just one line per commit.  Instead the commit
colorized to indicate the validity of the signed commit object,
using the faces named @code{magit-signature-*} (which see).

For a description of @code{magit-log-margin} see @ref{Log Margin}.

@node Log Margin
@subsection Log Margin

In buffers which show one or more logs, it is possible to show
additional information about each commit in the margin.  The options
used to configure the margin are named @code{magit-INFIX-margin}, where INFIX
is the same as in the respective major-mode @code{magit-INFIX-mode}.  In
regular log buffers that would be @code{magit-log-margin}.

@defopt magit-log-margin

This option specifies whether the margin is initially shown in
Magit-Log mode buffers and how it is formatted.

The value has the form @code{(INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH)}.

@itemize
@item
If INIT is non-nil, then the margin is shown initially.

@item
STYLE controls how to format the author or committer date.  It can
be one of @code{age} (to show the age of the commit), @code{age-abbreviated} (to
abbreviate the time unit to a character), or a string (suitable
for @code{format-time-string}) to show the actual date.  Option
@code{magit-log-margin-show-committer-date} controls which date is being
displayed.

@item
WIDTH controls the width of the margin.  This exists for forward
compatibility and currently the value should not be changed.

@item
AUTHOR controls whether the name of the author is also shown by
default.

@item
AUTHOR-WIDTH has to be an integer.  When the name of the author
is shown, then this specifies how much space is used to do so.
@end itemize
@end defopt

You can change the STYLE and AUTHOR-WIDTH of all @code{magit-INFIX-margin}
options to the same values by customizing @code{magit-log-margin} @strong{before}
@code{magit} is loaded.  If you do that, then the respective values for the
other options will default to what you have set for that variable.
Likewise if you set INIT in @code{magit-log-margin} to @code{nil}, then that is used
in the default of all other options.  But setting it to @code{t}, i.e.
re-enforcing the default for that option, does not carry to other
options.

@defopt magit-log-margin-show-committer-date

This option specifies whether to show the committer date in the
margin.  This option only controls whether the committer date is
displayed instead of the author date.  Whether some date is
displayed in the margin and whether the margin is displayed at all
is controlled by other options.
@end defopt

@table @asis
@kindex L
@cindex magit-margin-settings
@item @kbd{L} @tie{}@tie{}@tie{}@tie{}(@code{magit-margin-settings})

This transient prefix command binds the following suffix commands,
each of which changes the appearance of the margin in some way.
@end table

In some buffers that support the margin, @code{L} is instead bound to
@code{magit-log-refresh}, but that transient features the same commands, and
then some other unrelated commands.

@table @asis
@kindex L L
@cindex magit-toggle-margin
@item @kbd{L L} @tie{}@tie{}@tie{}@tie{}(@code{magit-toggle-margin})

This command shows or hides the margin.

@kindex L l
@cindex magit-cycle-margin-style
@item @kbd{L l} @tie{}@tie{}@tie{}@tie{}(@code{magit-cycle-margin-style})

This command cycles the style used for the margin.

@kindex L d
@cindex magit-toggle-margin-details
@item @kbd{L d} @tie{}@tie{}@tie{}@tie{}(@code{magit-toggle-margin-details})

This command shows or hides details in the margin.
@end table

@node Select from Log
@subsection Select from Log

When the user has to select a recent commit that is reachable from
@code{HEAD}, using regular completion would be inconvenient (because most
humans cannot remember hashes or "HEAD~5", at least not without double
checking).  Instead a log buffer is used to select the commit, which
has the advantage that commits are presented in order and with the
commit message.

Such selection logs are used when selecting the beginning of a rebase
and when selecting the commit to be squashed into.

In addition to the key bindings available in all log buffers, the
following additional key bindings are available in selection log
buffers:

@table @asis
@kindex C-c C-c
@cindex magit-log-select-pick
@item @kbd{C-c C-c} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-select-pick})

Select the commit at point and act on it.  Call
@code{magit-log-select-pick-function} with the selected commit as
argument.

@kindex C-c C-k
@cindex magit-log-select-quit
@item @kbd{C-c C-k} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-select-quit})

Abort selecting a commit, don't act on any commit.

@end table

@defopt magit-log-select-margin

This option specifies whether the margin is initially shown in
Magit-Log-Select mode buffers and how it is formatted.

The value has the form @code{(INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH)}.

@itemize
@item
If INIT is non-nil, then the margin is shown initially.

@item
STYLE controls how to format the author or committer date.  It can
be one of @code{age} (to show the age of the commit), @code{age-abbreviated} (to
abbreviate the time unit to a character), or a string (suitable
for @code{format-time-string}) to show the actual date.  Option
@code{magit-log-margin-show-committer-date} controls which date is being
displayed.

@item
WIDTH controls the width of the margin.  This exists for forward
compatibility and currently the value should not be changed.

@item
AUTHOR controls whether the name of the author is also shown by
default.

@item
AUTHOR-WIDTH has to be an integer.  When the name of the author
is shown, then this specifies how much space is used to do so.
@end itemize
@end defopt

@node Reflog
@subsection Reflog

Also see 
@ifinfo
@ref{git-reflog,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-reflog">git-reflog(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-reflog(1) manpage.
@end iftex

These reflog commands are available from the log transient.  See
@ref{Logging}.

@table @asis
@kindex l r
@cindex magit-reflog-current
@item @kbd{l r} @tie{}@tie{}@tie{}@tie{}(@code{magit-reflog-current})

Display the reflog of the current branch.

@kindex l O
@cindex magit-reflog-other
@item @kbd{l O} @tie{}@tie{}@tie{}@tie{}(@code{magit-reflog-other})

Display the reflog of a branch or another ref.

@kindex l H
@cindex magit-reflog-head
@item @kbd{l H} @tie{}@tie{}@tie{}@tie{}(@code{magit-reflog-head})

Display the @code{HEAD} reflog.

@end table

@defopt magit-reflog-margin

This option specifies whether the margin is initially shown in
Magit-Reflog mode buffers and how it is formatted.

The value has the form @code{(INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH)}.

@itemize
@item
If INIT is non-nil, then the margin is shown initially.

@item
STYLE controls how to format the author or committer date.  It can
be one of @code{age} (to show the age of the commit), @code{age-abbreviated} (to
abbreviate the time unit to a character), or a string (suitable
for @code{format-time-string}) to show the actual date.  Option
@code{magit-log-margin-show-committer-date} controls which date is being
displayed.

@item
WIDTH controls the width of the margin.  This exists for forward
compatibility and currently the value should not be changed.

@item
AUTHOR controls whether the name of the author is also shown by
default.

@item
AUTHOR-WIDTH has to be an integer.  When the name of the author
is shown, then this specifies how much space is used to do so.
@end itemize
@end defopt

@node Cherries
@subsection Cherries

Cherries are commits that haven't been applied upstream (yet), and are
usually visualized using a log.  Each commit is prefixed with @code{-} if it
has an equivalent in the upstream and @code{+} if it does not, i.e. if it is
a cherry.

The command @code{magit-cherry} shows cherries for a single branch, but the
references buffer (see @ref{References Buffer}) can show cherries for
multiple "upstreams" at once.

Also see 
@ifinfo
@ref{git-reflog,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-reflog">git-reflog(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-reflog(1) manpage.
@end iftex

@table @asis
@kindex Y
@cindex magit-cherry
@item @kbd{Y} @tie{}@tie{}@tie{}@tie{}(@code{magit-cherry})

Show commits that are in a certain branch but that have not been
merged in the upstream branch.

@end table

@defopt magit-cherry-margin

This option specifies whether the margin is initially shown in
Magit-Cherry mode buffers and how it is formatted.

The value has the form @code{(INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH)}.

@itemize
@item
If INIT is non-nil, then the margin is shown initially.

@item
STYLE controls how to format the author or committer date.  It can
be one of @code{age} (to show the age of the commit), @code{age-abbreviated} (to
abbreviate the time unit to a character), or a string (suitable
for @code{format-time-string}) to show the actual date.  Option
@code{magit-log-margin-show-committer-date} controls which date is being
displayed.

@item
WIDTH controls the width of the margin.  This exists for forward
compatibility and currently the value should not be changed.

@item
AUTHOR controls whether the name of the author is also shown by
default.

@item
AUTHOR-WIDTH has to be an integer.  When the name of the author
is shown, then this specifies how much space is used to do so.
@end itemize
@end defopt

@node Diffing
@section Diffing

The status buffer contains diffs for the staged and unstaged commits,
but that obviously isn't enough.  The transient prefix command
@code{magit-diff}, on @code{d}, features several suffix commands, which show a
specific diff in a separate diff buffer.

Like other transient prefix commands, @code{magit-diff} also features several
infix arguments that can be changed before invoking one of the suffix
commands.  However, in the case of the diff transient, these arguments may
be taken from those currently in use in the current repository's diff
buffer, depending on the value of @code{magit-prefix-use-buffer-arguments}
(see @ref{Transient Arguments and Buffer Variables}).

Also see 
@ifinfo
@ref{git-diff,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-diff">git-diff(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-diff(1) manpage.
@end iftex

@table @asis
@kindex d
@cindex magit-diff
@item @kbd{d} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.

@kindex d d
@cindex magit-diff-dwim
@item @kbd{d d} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-dwim})

Show changes for the thing at point.

@kindex d r
@cindex magit-diff-range
@item @kbd{d r} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-range})

Show differences between two commits.

RANGE should be a range (A..B or A@dots{}B) but can also be a single
commit.  If one side of the range is omitted, then it defaults to
@code{HEAD}.  If just a commit is given, then changes in the working tree
relative to that commit are shown.

If the region is active, use the revisions on the first and last
line of the region.  With a prefix argument, instead of diffing the
revisions, choose a revision to view changes along, starting at the
common ancestor of both revisions (i.e., use a "@dots{}"  range).

@kindex d w
@cindex magit-diff-working-tree
@item @kbd{d w} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-working-tree})

Show changes between the current working tree and the @code{HEAD} commit.
With a prefix argument show changes between the working tree and a
commit read from the minibuffer.

@kindex d s
@cindex magit-diff-staged
@item @kbd{d s} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-staged})

Show changes between the index and the @code{HEAD} commit.  With a prefix
argument show changes between the index and a commit read from the
minibuffer.

@kindex d u
@cindex magit-diff-unstaged
@item @kbd{d u} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-unstaged})

Show changes between the working tree and the index.

@kindex d p
@cindex magit-diff-paths
@item @kbd{d p} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-paths})

Show changes between any two files on disk.
@end table

All of the above suffix commands update the repository's diff buffer.
The diff transient also features two commands which show differences
in another buffer:

@table @asis
@kindex d c
@cindex magit-show-commit
@item @kbd{d c} @tie{}@tie{}@tie{}@tie{}(@code{magit-show-commit})

Show the commit at point.  If there is no commit at point or with a
prefix argument, prompt for a commit.

@kindex d t
@cindex magit-stash-show
@item @kbd{d t} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-show})

Show all diffs of a stash in a buffer.
@end table

Two additional commands that show the diff for the file or blob that
is being visited in the current buffer exists, see @ref{Minor Mode for Buffers Visiting Files}.

@menu
* Refreshing Diffs::
* Commands Available in Diffs::
* Diff Options::
* Revision Buffer::
@end menu

@node Refreshing Diffs
@subsection Refreshing Diffs

The transient prefix command @code{magit-diff-refresh}, on @code{D}, can be used to
change the diff arguments used in the current buffer, without changing
which diff is shown.  This works in dedicated diff buffers, but also
in the status buffer.

@table @asis
@kindex D
@cindex magit-diff-refresh
@item @kbd{D} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-refresh})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.

@kindex D g
@cindex magit-diff-refresh
@item @kbd{D g} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-refresh})

This suffix command sets the local diff arguments for the current
buffer.

@kindex D s
@cindex magit-diff-set-default-arguments
@item @kbd{D s} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-set-default-arguments})

This suffix command sets the default diff arguments for buffers of
the same type as that of the current buffer.  Other existing buffers
of the same type are not affected because their local values have
already been initialized.

@kindex D w
@cindex magit-diff-save-default-arguments
@item @kbd{D w} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-save-default-arguments})

This suffix command sets the default diff arguments for buffers of
the same type as that of the current buffer, and saves the value for
future sessions.  Other existing buffers of the same type are not
affected because their local values have already been initialized.

@kindex D t
@cindex magit-diff-toggle-refine-hunk
@item @kbd{D t} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-toggle-refine-hunk})

This command toggles hunk refinement on or off.

@kindex D r
@cindex magit-diff-switch-range-type
@item @kbd{D r} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-switch-range-type})

This command converts the diff range type from "revA..revB" to
"revB@dots{}revA", or vice versa.

@kindex D f
@cindex magit-diff-flip-revs
@item @kbd{D f} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-flip-revs})

This command swaps revisions in the diff range from "revA..revB"
to "revB..revA", or vice versa.

@kindex D F
@cindex magit-diff-toggle-file-filter
@item @kbd{D F} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-toggle-file-filter})

This command toggles the file restriction of the diffs in the
current buffer, allowing you to quickly switch between viewing all
the changes in the commit and the restricted subset.  As a special
case, when this command is called from a log buffer, it toggles the
file restriction in the repository's revision buffer, which is
useful when you display a revision from a log buffer that is
restricted to a file or files.
@end table

In addition to the above transient, which allows changing any of the
supported arguments, there also exist some commands that change only
a particular argument.

@table @asis
@kindex -
@cindex magit-diff-less-context
@item @kbd{-} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-less-context})

This command decreases the context for diff hunks by COUNT lines.

@kindex +
@cindex magit-diff-more-context
@item @kbd{+} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-more-context})

This command increases the context for diff hunks by COUNT lines.

@kindex 0
@cindex magit-diff-default-context
@item @kbd{0} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-default-context})

This command resets the context for diff hunks to the default height.
@end table

The following commands quickly change what diff is being displayed
without having to using one of the diff transient.

@table @asis
@kindex C-c C-d
@cindex magit-diff-while-committing
@item @kbd{C-c C-d} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-while-committing})

While committing, this command shows the changes that are about to
be committed.  While amending, invoking the command again toggles
between showing just the new changes or all the changes that will be
committed.

This binding is available in the diff buffer as well as the commit
message buffer.

@kindex C-c C-b
@cindex magit-go-backward
@item @kbd{C-c C-b} @tie{}@tie{}@tie{}@tie{}(@code{magit-go-backward})

This command moves backward in current buffer's history.

@kindex C-c C-f
@cindex magit-go-forward
@item @kbd{C-c C-f} @tie{}@tie{}@tie{}@tie{}(@code{magit-go-forward})

This command moves forward in current buffer's history.
@end table

@node Commands Available in Diffs
@subsection Commands Available in Diffs

Some commands are only available if point is inside a diff.

@code{magit-diff-visit-file} and related commands visit the appropriate
version of the file that the diff at point is about.  Likewise
@code{magit-diff-visit-worktree-file} and related commands visit the worktree
version of the file that the diff at point is about.  See @ref{Visiting Files and Blobs from a Diff} for more information and the key bindings.

@table @asis
@kindex C-c C-t
@cindex magit-diff-trace-definition
@item @kbd{C-c C-t} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-trace-definition})

This command shows a log for the definition at point.

@end table

@defopt magit-log-trace-definition-function

The function specified by this option is used by
@code{magit-log-trace-definition} to determine the function at point.  For
major-modes that have special needs, you could set the local value
using the mode's hook.
@end defopt

@table @asis
@kindex C-c C-e
@cindex magit-diff-edit-hunk-commit
@item @kbd{C-c C-e} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-edit-hunk-commit})

From a hunk, this command edits the respective commit and visits
the file.

First it visits the file being modified by the hunk at the correct
location using @code{magit-diff-visit-file}.  This actually visits a blob.
When point is on a diff header, not within an individual hunk, then
this visits the blob the first hunk is about.

Then it invokes @code{magit-edit-line-commit}, which uses an interactive
rebase to make the commit editable, or if that is not possible
because the commit is not reachable from @code{HEAD} by checking out that
commit directly.  This also causes the actual worktree file to be
visited.

Neither the blob nor the file buffer are killed when finishing
the rebase.  If that is undesirable, then it might be better to
use @code{magit-rebase-edit-command} instead of this command.

@kindex j
@cindex magit-jump-to-diffstat-or-diff
@item @kbd{j} @tie{}@tie{}@tie{}@tie{}(@code{magit-jump-to-diffstat-or-diff})

This command jumps to the diffstat or diff.  When point is on a file
inside the diffstat section, then jump to the respective diff
section.  Otherwise, jump to the diffstat section or a child
thereof.
@end table

The next two commands are not specific to Magit-Diff mode (or and
Magit buffer for that matter), but it might be worth pointing out
that they are available here too.

@table @asis
@kindex SPC
@cindex scroll-up
@item @kbd{SPC} @tie{}@tie{}@tie{}@tie{}(@code{scroll-up})

This command scrolls text upward.

@kindex DEL
@cindex scroll-down
@item @kbd{DEL} @tie{}@tie{}@tie{}@tie{}(@code{scroll-down})

This command scrolls text downward.
@end table

@node Diff Options
@subsection Diff Options

@defopt magit-diff-refine-hunk

Whether to show word-granularity differences within diff hunks.

@itemize
@item
@code{nil} Never show fine differences.

@item
@code{t} Show fine differences for the current diff hunk only.

@item
@code{all} Show fine differences for all displayed diff hunks.
@end itemize
@end defopt

@defopt magit-diff-refine-ignore-whitespace

Whether to ignore whitespace changes in word-granularity
differences.
@end defopt

@defopt magit-diff-adjust-tab-width

Whether to adjust the width of tabs in diffs.

Determining the correct width can be expensive if it requires
opening large and/or many files, so the widths are cached in the
variable @code{magit-diff--tab-width-cache}.  Set that to nil to invalidate
the cache.

@itemize
@item
@code{nil} Never adjust tab width.  Use `tab-width's value from the Magit
buffer itself instead.


@item
@code{t} If the corresponding file-visiting buffer exits, then use
@code{tab-width}'s value from that buffer.  Doing this is cheap, so this
value is used even if a corresponding cache entry exists.


@item
@code{always} If there is no such buffer, then temporarily visit the file
to determine the value.


@item
NUMBER Like @code{always}, but don't visit files larger than NUMBER
bytes.
@end itemize
@end defopt

@defopt magit-diff-paint-whitespace

Specify where to highlight whitespace errors.

See @code{magit-diff-highlight-trailing},
@code{magit-diff-highlight-indentation}.  The symbol @code{t} means in all
diffs, @code{status} means only in the status buffer, and nil means
nowhere.

@itemize
@item
@code{nil} Never highlight whitespace errors.

@item
@code{t} Highlight whitespace errors everywhere.

@item
@code{uncommitted} Only highlight whitespace errors in diffs showing
uncommitted changes.  For backward compatibility @code{status} is treated
as a synonym.
@end itemize
@end defopt

@defopt magit-diff-paint-whitespace-lines

Specify in what kind of lines to highlight whitespace errors.

@itemize
@item
@code{t} Highlight only in added lines.

@item
@code{both} Highlight in added and removed lines.

@item
@code{all} Highlight in added, removed and context lines.
@end itemize
@end defopt

@defopt magit-diff-highlight-trailing

Whether to highlight whitespace at the end of a line in diffs.  Used
only when @code{magit-diff-paint-whitespace} is non-nil.
@end defopt

@defopt magit-diff-highlight-indentation

This option controls whether to highlight the indentation in case it
used the "wrong" indentation style.  Indentation is only highlighted
if @code{magit-diff-paint-whitespace} is also non-nil.

The value is an alist of the form @code{((REGEXP . INDENT)...)}.  The path
to the current repository is matched against each element in reverse
order.  Therefore if a REGEXP matches, then earlier elements are not
tried.

If the used INDENT is @code{tabs}, highlight indentation with tabs.  If
INDENT is an integer, highlight indentation with at least that many
spaces.  Otherwise, highlight neither.
@end defopt

@defopt magit-diff-hide-trailing-cr-characters

Whether to hide ^M characters at the end of a line in diffs.
@end defopt

@defopt magit-diff-highlight-hunk-region-functions

This option specifies the functions used to highlight the
hunk-internal region.

@code{magit-diff-highlight-hunk-region-dim-outside} overlays the outside of
the hunk internal selection with a face that causes the added and
removed lines to have the same background color as context lines.
This function should not be removed from the value of this option.

@code{magit-diff-highlight-hunk-region-using-overlays} and
@code{magit-diff-highlight-hunk-region-using-underline} emphasize the
region by placing delimiting horizontal lines before and after it.
Both of these functions have glitches which cannot be fixed due to
limitations of Emacs' display engine.  For more information see
@uref{https://github.com/magit/magit/issues/2758} ff.

Instead of, or in addition to, using delimiting horizontal lines,
to emphasize the boundaries, you may which to emphasize the text
itself, using @code{magit-diff-highlight-hunk-region-using-face}.

In terminal frames it's not possible to draw lines as the overlay
and underline variants normally do, so there they fall back to
calling the face function instead.
@end defopt

@defopt magit-diff-unmarked-lines-keep-foreground

This option controls whether added and removed lines outside the
hunk-internal region only lose their distinct background color or
also the foreground color.  Whether the outside of the region is
dimmed at all depends on @code{magit-diff-highlight-hunk-region-functions}.
@end defopt

@node Revision Buffer
@subsection Revision Buffer

@defopt magit-revision-insert-related-refs

Whether to show related branches in revision buffers.

@itemize
@item
@code{nil} Don't show any related branches.

@item
@code{t} Show related local branches.

@item
@code{all} Show related local and remote branches.

@item
@code{mixed} Show all containing branches and local merged branches.
@end itemize
@end defopt

@defopt magit-revision-show-gravatars

Whether to show gravatar images in revision buffers.

If @code{nil}, then don't insert any gravatar images.  If @code{t}, then insert
both images.  If @code{author} or @code{committer}, then insert only the
respective image.

If you have customized the option @code{magit-revision-headers-format}
and want to insert the images then you might also have to specify
where to do so.  In that case the value has to be a cons-cell of
two regular expressions.  The car specifies where to insert the
author's image.  The top half of the image is inserted right
after the matched text, the bottom half on the next line in the
same column.  The cdr specifies where to insert the committer's
image, accordingly.  Either the car or the cdr may be nil."
@end defopt

@defopt magit-revision-use-hash-sections

Whether to turn hashes inside the commit message into sections.

If non-nil, then hashes inside the commit message are turned into
@code{commit} sections.  There is a trade off to be made between
performance and reliability:

@itemize
@item
@code{slow} calls git for every word to be absolutely sure.

@item
@code{quick} skips words less than seven characters long.

@item
@code{quicker} additionally skips words that don't contain a number.

@item
@code{quickest} uses all words that are at least seven characters long
and which contain at least one number as well as at least one
letter.
@end itemize

If nil, then no hashes are turned into sections, but you can still
visit the commit at point using "RET".
@end defopt

The diffs shown in the revision buffer may be automatically restricted
to a subset of the changed files.  If the revision buffer is displayed
from a log buffer, the revision buffer will share the same file
restriction as that log buffer (also see the command
@code{magit-diff-toggle-file-filter}).

@defopt magit-revision-filter-files-on-follow

Whether showing a commit from a log buffer honors the log's file
filter when the log arguments include @code{--follow}.

When this option is nil, displaying a commit from a log ignores the
log's file filter if the log arguments include @code{--follow}.  Doing so
avoids showing an empty diff in revision buffers for commits before
a rename event.  In such cases, the @code{--patch} argument of the log
transient can be used to show the file-restricted diffs inline.

Set this option to non-nil to keep the log's file restriction even
if @code{--follow} is present in the log arguments.
@end defopt

If the revision buffer is not displayed from a log buffer, the file
restriction is determined as usual (see @ref{Transient Arguments and Buffer Variables}).

@node Ediffing
@section Ediffing

This section describes how to enter Ediff from Magit buffers.  For
information on how to use Ediff itself, see @ref{Top,,,ediff,}.

@table @asis
@kindex e
@cindex magit-ediff-dwim
@item @kbd{e} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-dwim})

Compare, stage, or resolve using Ediff.

This command tries to guess what file, and what commit or range the
user wants to compare, stage, or resolve using Ediff.  It might only
be able to guess either the file, or range/commit, in which case
the user is asked about the other.  It might not always guess right,
in which case the appropriate @code{magit-ediff-*} command has to be used
explicitly.  If it cannot read the user's mind at all, then it asks
the user for a command to run.

@kindex E
@cindex magit-ediff
@item @kbd{E} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff})

This transient prefix command binds the following suffix commands
and displays them in a temporary buffer until a suffix is invoked.

@kindex E r
@cindex magit-ediff-compare
@item @kbd{E r} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-compare})

Compare two revisions of a file using Ediff.

If the region is active, use the revisions on the first and last
line of the region.  With a prefix argument, instead of diffing the
revisions, choose a revision to view changes along, starting at the
common ancestor of both revisions (i.e., use a "@dots{}"  range).

@kindex E m
@cindex magit-ediff-resolve
@item @kbd{E m} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-resolve})

Resolve outstanding conflicts in a file using Ediff, defaulting to
the file at point.

Provided that the value of @code{merge.conflictstyle} is @code{diff3}, you can
view the file's merge-base revision using @code{/} in the Ediff control
buffer.

In the rare event that you want to manually resolve all conflicts,
including those already resolved by Git, use
@code{ediff-merge-revisions-with-ancestor}.

@kindex E s
@cindex magit-ediff-stage
@item @kbd{E s} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-stage})

Stage and unstage changes to a file using Ediff, defaulting to the
file at point.

@kindex E u
@cindex magit-ediff-show-unstaged
@item @kbd{E u} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-show-unstaged})

Show unstaged changes to a file using Ediff.

@kindex E i
@cindex magit-ediff-show-staged
@item @kbd{E i} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-show-staged})

Show staged changes to a file using Ediff.

@kindex E w
@cindex magit-ediff-show-working-tree
@item @kbd{E w} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-show-working-tree})

Show changes in a file between @code{HEAD} and working tree using Ediff.

@kindex E c
@cindex magit-ediff-show-commit
@item @kbd{E c} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-show-commit})

Show changes to a file introduced by a commit using Ediff.

@kindex E z
@cindex magit-ediff-show-stash
@item @kbd{E z} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-show-stash})

Show changes to a file introduced by a stash using Ediff.

@end table

@defopt magit-ediff-dwim-show-on-hunks

This option controls what command @code{magit-ediff-dwim} calls when
point is on uncommitted hunks.  When nil, always run
@code{magit-ediff-stage}.  Otherwise, use @code{magit-ediff-show-staged} and
@code{magit-ediff-show-unstaged} to show staged and unstaged changes,
respectively.
@end defopt

@defopt magit-ediff-show-stash-with-index

This option controls whether @code{magit-ediff-show-stash} includes a
buffer containing the file's state in the index at the time the
stash was created.  This makes it possible to tell which changes in
the stash were staged.
@end defopt

@defopt magit-ediff-quit-hook

This hook is run after quitting an Ediff session that was created
using a Magit command.  The hook functions are run inside the Ediff
control buffer, and should not change the current buffer.

This is similar to @code{ediff-quit-hook} but takes the needs of Magit into
account.  The regular @code{ediff-quit-hook} is ignored by Ediff sessions
that were created using a Magit command.
@end defopt

@node References Buffer
@section References Buffer

@table @asis
@kindex y
@cindex magit-show-refs
@item @kbd{y} @tie{}@tie{}@tie{}@tie{}(@code{magit-show-refs})

This command lists branches and tags in a dedicated buffer.

However if this command is invoked again from this buffer or if it
is invoked with a prefix argument, then it acts as a transient
prefix command, which binds the following suffix commands and some
infix arguments.
@end table

All of the following suffix commands list exactly the same branches
and tags.  The only difference the optional feature that can be
enabled by changing the value of @code{magit-refs-show-commit-count} (see
below).  These commands specify a different branch or commit against
which all the other references are compared.

@table @asis
@kindex y y
@cindex magit-show-refs-head
@item @kbd{y y} @tie{}@tie{}@tie{}@tie{}(@code{magit-show-refs-head})

This command lists branches and tags in a dedicated buffer.  Each
reference is being compared with @code{HEAD}.

@kindex y c
@cindex magit-show-refs-current
@item @kbd{y c} @tie{}@tie{}@tie{}@tie{}(@code{magit-show-refs-current})

This command lists branches and tags in a dedicated buffer.  Each
reference is being compared with the current branch or @code{HEAD} if it
is detached.

@kindex y o
@cindex magit-show-refs-other
@item @kbd{y o} @tie{}@tie{}@tie{}@tie{}(@code{magit-show-refs-other})

This command lists branches and tags in a dedicated buffer.  Each
reference is being compared with a branch read from the user.

@end table

@defopt magit-refs-show-commit-count

Whether to show commit counts in Magit-Refs mode buffers.

@itemize
@item
@code{all} Show counts for branches and tags.

@item
@code{branch} Show counts for branches only.

@item
@code{nil} Never show counts.
@end itemize

The default is @code{nil} because anything else can be very expensive.
@end defopt

@defopt magit-refs-pad-commit-counts

Whether to pad all commit counts on all sides in Magit-Refs mode
buffers.

If this is nil, then some commit counts are displayed right next to
one of the branches that appear next to the count, without any space
in between.  This might look bad if the branch name faces look too
similar to @code{magit-dimmed}.

If this is non-nil, then spaces are placed on both sides of all
commit counts.
@end defopt

@defopt magit-refs-show-remote-prefix

Whether to show the remote prefix in lists of remote branches.

Showing the prefix is redundant because the name of the remote is
already shown in the heading preceding the list of its branches.
@end defopt

@defopt magit-refs-primary-column-width

Width of the primary column in `magit-refs-mode' buffers.  The
primary column is the column that contains the name of the branch
that the current row is about.

If this is an integer, then the column is that many columns wide.
Otherwise it has to be a cons-cell of two integers.  The first
specifies the minimal width, the second the maximal width.  In that
case the actual width is determined using the length of the names of
the shown local branches.  (Remote branches and tags are not taken
into account when calculating to optimal width.)
@end defopt

@defopt magit-refs-focus-column-width

Width of the focus column in `magit-refs-mode' buffers.

The focus column is the first column, which marks one branch
(usually the current branch) as the focused branch using @code{*} or @code{@@}.
For each other reference, this column optionally shows how many
commits it is ahead of the focused branch and @code{<}, or if it isn't
ahead then the commits it is behind and @code{>}, or if it isn't behind
either, then a @code{=}.

This column may also display only @code{*} or @code{@@} for the focused branch, in
which case this option is ignored.  Use @code{L v} to change the verbosity
of this column.
@end defopt

@defopt magit-refs-margin

This option specifies whether the margin is initially shown in
Magit-Refs mode buffers and how it is formatted.

The value has the form @code{(INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH)}.

@itemize
@item
If INIT is non-nil, then the margin is shown initially.

@item
STYLE controls how to format the author or committer date.  It can
be one of @code{age} (to show the age of the commit), @code{age-abbreviated} (to
abbreviate the time unit to a character), or a string (suitable
for @code{format-time-string}) to show the actual date.  Option
@code{magit-log-margin-show-committer-date} controls which date is being
displayed.

@item
WIDTH controls the width of the margin.  This exists for forward
compatibility and currently the value should not be changed.

@item
AUTHOR controls whether the name of the author is also shown by
default.

@item
AUTHOR-WIDTH has to be an integer.  When the name of the author
is shown, then this specifies how much space is used to do so.
@end itemize
@end defopt

@defopt magit-refs-margin-for-tags

This option specifies whether to show information about tags in the
margin.  This is disabled by default because it is slow if there are
many tags.
@end defopt

The following variables control how individual refs are displayed.  If
you change one of these variables (especially the "%c" part), then you
should also change the others to keep things aligned.  The following
%-sequences are supported:

@itemize
@item
@code{%a} Number of commits this ref has over the one we compare to.

@item
@code{%b} Number of commits the ref we compare to has over this one.

@item
@code{%c} Number of commits this ref has over the one we compare to.  For
the ref which all other refs are compared this is instead "@@", if
it is the current branch, or "#" otherwise.

@item
@code{%C} For the ref which all other refs are compared this is "@@", if it
is the current branch, or "#" otherwise.  For all other refs " ".

@item
@code{%h} Hash of this ref's tip.

@item
@code{%m} Commit summary of the tip of this ref.

@item
@code{%n} Name of this ref.

@item
@code{%u} Upstream of this local branch.

@item
@code{%U} Upstream of this local branch and additional local vs. upstream
information.

@end itemize

@defopt magit-refs-filter-alist

The purpose of this option is to forgo displaying certain refs
based on their name.  If you want to not display any refs of a
certain type, then you should remove the appropriate function
from @code{magit-refs-sections-hook} instead.

This alist controls which tags and branches are omitted from being
displayed in @code{magit-refs-mode} buffers.  If it is @code{nil}, then all refs
are displayed (subject to @code{magit-refs-sections-hook}).

All keys are tried in order until one matches.  Then its value is
used and subsequent elements are ignored.  If the value is non-nil,
then the reference is displayed, otherwise it is not.  If no element
matches, then the reference is displayed.

A key can either be a regular expression that the refname has to
match, or a function that takes the refname as only argument and
returns a boolean.  A remote branch such as "origin/master" is
displayed as just "master", however for this comparison the
former is used.
@end defopt

@table @asis
@kindex RET
@cindex magit-visit-ref
@item @kbd{RET} @tie{}@tie{}@tie{}@tie{}(@code{magit-visit-ref})

This command visits the reference or revision at point in another
buffer.  If there is no revision at point or with a prefix argument
then it prompts for a revision.

This command behaves just like @code{magit-show-commit} as described above,
except if point is on a reference in a @code{magit-refs-mode} buffer, in
which case the behavior may be different, but only if you have
customized the option @code{magit-visit-ref-behavior}.

@end table

@defopt magit-visit-ref-behavior

This option controls how @code{magit-visit-ref} behaves in @code{magit-refs-mode}
buffers.

By default @code{magit-visit-ref} behaves like @code{magit-show-commit}, in all
buffers, including @code{magit-refs-mode} buffers.  When the type of the
section at point is @code{commit} then "RET" is bound to @code{magit-show-commit},
and when the type is either @code{branch} or @code{tag} then it is bound to
@code{magit-visit-ref}.

"RET" is one of Magit's most essential keys and at least by default
it should behave consistently across all of Magit, especially
because users quickly learn that it does something very harmless; it
shows more information about the thing at point in another buffer.

However "RET" used to behave differently in @code{magit-refs-mode} buffers,
doing surprising things, some of which cannot really be described as
"visit this thing".  If you've grown accustomed this behavior, you
can restore it by adding one or more of the below symbols to the
value of this option.  But keep in mind that by doing so you don't
only introduce inconsistencies, you also lose some functionality and
might have to resort to @code{M-x magit-show-commit} to get it back.

@code{magit-visit-ref} looks for these symbols in the order in which they
are described here.  If the presence of a symbol applies to the
current situation, then the symbols that follow do not affect the
outcome.

@itemize
@item
@code{focus-on-ref}

With a prefix argument update the buffer to show commit counts
and lists of cherry commits relative to the reference at point
instead of relative to the current buffer or @code{HEAD}.

Instead of adding this symbol, consider pressing "C-u y o RET".


@item
@code{create-branch}

If point is on a remote branch, then create a new local branch
with the same name, use the remote branch as its upstream, and
then check out the local branch.

Instead of adding this symbol, consider pressing "b c RET RET",
like you would do in other buffers.


@item
@code{checkout-any}

Check out the reference at point.  If that reference is a tag
or a remote branch, then this results in a detached @code{HEAD}.

Instead of adding this symbol, consider pressing "b b RET",
like you would do in other buffers.


@item
@code{checkout-branch}

Check out the local branch at point.

Instead of adding this symbol, consider pressing "b b RET",
like you would do in other buffers.
@end itemize
@end defopt

@menu
* References Sections::
@end menu

@node References Sections
@subsection References Sections

The contents of references buffers is controlled using the hook
@code{magit-refs-sections-hook}.  See @ref{Section Hooks} to learn about such hooks
and how to customize them.  All of the below functions are members of
the default value.  Note that it makes much less sense to customize
this hook than it does for the respective hook used for the status
buffer.

@defopt magit-refs-sections-hook

Hook run to insert sections into a references buffer.
@end defopt

@defun magit-insert-local-branches

Insert sections showing all local branches.
@end defun

@defun magit-insert-remote-branches

Insert sections showing all remote-tracking branches.
@end defun

@defun magit-insert-tags

Insert sections showing all tags.
@end defun

@node Bisecting
@section Bisecting

Also see 
@ifinfo
@ref{git-bisect,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-bisect">git-bisect(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-bisect(1) manpage.
@end iftex

@table @asis
@kindex B
@cindex magit-bisect
@item @kbd{B} @tie{}@tie{}@tie{}@tie{}(@code{magit-bisect})

This transient prefix command binds the following suffix commands
and displays them in a temporary buffer until a suffix is invoked.
@end table

When bisecting is not in progress, then the transient features the
following suffix commands.

@table @asis
@kindex B B
@cindex magit-bisect-start
@item @kbd{B B} @tie{}@tie{}@tie{}@tie{}(@code{magit-bisect-start})

Start a bisect session.

Bisecting a bug means to find the commit that introduced it.
This command starts such a bisect session by asking for a known
good and a bad commit.

@kindex B s
@cindex magit-bisect-run
@item @kbd{B s} @tie{}@tie{}@tie{}@tie{}(@code{magit-bisect-run})

Bisect automatically by running commands after each step.
@end table

When bisecting in progress, then the transient instead features the
following suffix commands.

@table @asis
@kindex B b
@cindex magit-bisect-bad
@item @kbd{B b} @tie{}@tie{}@tie{}@tie{}(@code{magit-bisect-bad})

Mark the current commit as bad.  Use this after you have asserted
that the commit does contain the bug in question.

@kindex B g
@cindex magit-bisect-good
@item @kbd{B g} @tie{}@tie{}@tie{}@tie{}(@code{magit-bisect-good})

Mark the current commit as good.  Use this after you have asserted
that the commit does not contain the bug in question.

@kindex B k
@cindex magit-bisect-skip
@item @kbd{B k} @tie{}@tie{}@tie{}@tie{}(@code{magit-bisect-skip})

Skip the current commit.  Use this if for some reason the current
commit is not a good one to test.  This command lets Git choose a
different one.

@kindex B r
@cindex magit-bisect-reset
@item @kbd{B r} @tie{}@tie{}@tie{}@tie{}(@code{magit-bisect-reset})

After bisecting, cleanup bisection state and return to original
@code{HEAD}.
@end table

By default the status buffer shows information about the ongoing
bisect session.

@defopt magit-bisect-show-graph

This option controls whether a graph is displayed for the log of
commits that still have to be bisected.
@end defopt

@node Visiting Files and Blobs
@section Visiting Files and Blobs

Magit provides several commands that visit a file or blob (the version
of a file that is stored in a certain commit).  Actually it provides
several @strong{groups} of such commands and the several @strong{variants} within each
group.

@menu
* General-Purpose Visit Commands::
* Visiting Files and Blobs from a Diff::
@end menu

@node General-Purpose Visit Commands
@subsection General-Purpose Visit Commands

These commands can be used anywhere to open any blob.  Currently no
keys are bound to these commands by default, but that is likely to
change.

@cindex magit-find-file
@deffn Command magit-find-file

This command reads a filename and revision from the user and visits
the respective blob in a buffer.  The buffer is displayed in the
selected window.
@end deffn

@cindex magit-find-file-other-window
@deffn Command magit-find-file-other-window

This command reads a filename and revision from the user and visits
the respective blob in a buffer.  The buffer is displayed in another
window.
@end deffn

@cindex magit-find-file-other-frame
@deffn Command magit-find-file-other-frame

This command reads a filename and revision from the user and visits
the respective blob in a buffer.  The buffer is displayed in another
frame.
@end deffn

@node Visiting Files and Blobs from a Diff
@subsection Visiting Files and Blobs from a Diff

These commands can only be used when point is inside a diff.

@table @asis
@kindex RET
@cindex magit-diff-visit-file
@item @kbd{RET} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-visit-file})

This command visits the appropriate version of the file that the
diff at point is about.

This commands visits the worktree version of the appropriate file.
The location of point inside the diff determines which file is being
visited.  The visited version depends on what changes the diff is
about.

@itemize
@item
If the diff shows uncommitted changes (i.e. staged or unstaged
changes), then visit the file in the working tree (i.e. the
same "real" file that @code{find-file} would visit.  In all other
cases visit a "blob" (i.e. the version of a file as stored
in some commit).


@item
If point is on a removed line, then visit the blob for the
first parent of the commit that removed that line, i.e. the
last commit where that line still exists.


@item
If point is on an added or context line, then visit the blob
that adds that line, or if the diff shows from more than a
single commit, then visit the blob from the last of these
commits.
@end itemize

In the file-visiting buffer this command goes to the line that
corresponds to the line that point is on in the diff.

The buffer is displayed in the selected window.  With a prefix
argument the buffer is displayed in another window instead.

@end table

@defopt magit-diff-visit-previous-blob

This option controls whether @code{magit-diff-visit-file} may visit the
previous blob.  When this is @code{t} (the default) and point is on a
removed line in a diff for a committed change, then
@code{magit-diff-visit-file} visits the blob from the last revision which
still had that line.

Currently this is only supported for committed changes, for staged
and unstaged changes @code{magit-diff-visit-file} always visits the file in
the working tree.
@end defopt

@table @asis
@kindex C-<return>
@cindex magit-diff-visit-file-worktree
@item @kbd{C-<return>} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-visit-file-worktree})

This command visits the worktree version of the appropriate file.
The location of point inside the diff determines which file is being
visited.  Unlike @code{magit-diff-visit-file} it always visits the "real"
file in the working tree, i.e the "current version" of the file.

In the file-visiting buffer this command goes to the line that
corresponds to the line that point is on in the diff.  Lines that
were added or removed in the working tree, the index and other
commits in between are automatically accounted for.

The buffer is displayed in the selected window.  With a prefix
argument the buffer is displayed in another window instead.
@end table

Variants of the above two commands exist that instead visit the file
in another window or in another frame.  If you prefer such behavior,
then you may want to change the above key bindings, but note that the
above commands also use another window when invoked with a prefix
argument.

@cindex magit-diff-visit-file-other-window
@deffn Command magit-diff-visit-file-other-window
@end deffn
@cindex magit-diff-visit-file-other-frame
@deffn Command magit-diff-visit-file-other-frame
@end deffn
@cindex magit-diff-visit-worktree-file-other-window
@deffn Command magit-diff-visit-worktree-file-other-window
@end deffn
@cindex magit-diff-visit-worktree-file-other-frame
@deffn Command magit-diff-visit-worktree-file-other-frame
@end deffn

@node Blaming
@section Blaming

Also see 
@ifinfo
@ref{git-blame,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-blame">git-blame(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-blame(1) manpage.
@end iftex

To start blaming invoke the @code{magit-file-dispatch} transient prefix
command by pressing @code{C-c M-g}.  (This is only the default binding and
the recommended binding is @code{C-c g}.  Also neither binding may be
available if you disabled @code{global-magit-file-mode}.  Also see @ref{Minor Mode for Buffers Visiting Files}.)

The blaming suffix commands can be invoked from the dispatch
transient.  However if you want to set an infix argument, then you
have to enter the blaming sub-transient first.

The key bindings shown below assume that you enter the dispatch
transient using the default binding.

@table @asis
@kindex C-c M-g B
@cindex magit-blame
@item @kbd{C-c M-g B} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.
@end table

Note that not all of the following suffixes are available at all
times.  For example if @code{magit-blame-mode} is not enabled, then the
command whose purpose is to turn off that mode would not be of any
use and therefore isn't available.

@table @asis
@kindex C-c M-g b
@cindex magit-blame-addition
@item @kbd{C-c M-g b} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-addition})
@kindex C-c M-g B b
@cindex magit-blame-addition
@item @kbd{C-c M-g B b} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-addition})

This command augments each line or chunk of lines in the current
file-visiting or blob-visiting buffer with information about what
commits last touched these lines.

If the buffer visits a revision of that file, then history up to
that revision is considered.  Otherwise, the file's full history is
considered, including uncommitted changes.

If Magit-Blame mode is already turned on in the current buffer then
blaming is done recursively, by visiting REVISION:FILE (using
@code{magit-find-file}), where REVISION is a parent of the revision that
added the current line or chunk of lines.

@kindex C-c M-g r
@cindex magit-blame-removal
@item @kbd{C-c M-g r} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-removal})
@kindex C-c M-g B r
@cindex magit-blame-removal
@item @kbd{C-c M-g B r} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-removal})

This command augments each line or chunk of lines in the current
blob-visiting buffer with information about the revision that
removes it.  It cannot be used in file-visiting buffers.

Like @code{magit-blame-addition}, this command can be used recursively.

@kindex C-c M-g f
@cindex magit-blame-reverse
@item @kbd{C-c M-g f} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-reverse})
@kindex C-c M-g B f
@cindex magit-blame-reverse
@item @kbd{C-c M-g B f} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-reverse})

This command augments each line or chunk of lines in the current
file-visiting or blob-visiting buffer with information about the
last revision in which a line still existed.

Like @code{magit-blame-addition}, this command can be used recursively.

@kindex C-c M-g e
@cindex magit-blame-echo
@item @kbd{C-c M-g e} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-echo})
@kindex C-c M-g B e
@cindex magit-blame-echo
@item @kbd{C-c M-g B e} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-echo})

This command is like @code{magit-blame-addition} except that it doesn't
turn on @code{read-only-mode} and that it initially uses the visualization
style specified by option @code{magit-blame-echo-style}.
@end table

The following key bindings are available when Magit-Blame mode is
enabled and Read-Only mode is not enabled.  These commands are also
available in other buffers; here only the behavior is described that
is relevant in file-visiting buffers that are being blamed.

@table @asis
@kindex RET
@cindex magit-show-commit
@item @kbd{RET} @tie{}@tie{}@tie{}@tie{}(@code{magit-show-commit})

This command shows the commit that last touched the line at point.

@kindex SPC
@cindex magit-diff-show-or-scroll-up
@item @kbd{SPC} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-show-or-scroll-up})

This command updates the commit buffer.

This either shows the commit that last touched the line at point in
the appropriate buffer, or if that buffer is already being displayed
in the current frame and if that buffer contains information about
that commit, then the buffer is scrolled up instead.

@kindex DEL
@cindex magit-diff-show-or-scroll-down
@item @kbd{DEL} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-show-or-scroll-down})

This command updates the commit buffer.

This either shows the commit that last touched the line at point in
the appropriate buffer, or if that buffer is already being displayed
in the current frame and if that buffer contains information about
that commit, then the buffer is scrolled down instead.
@end table

The following key bindings are available when both Magit-Blame mode
and Read-Only mode are enabled.

@table @asis
@kindex b
@cindex magit-blame
@item @kbd{b} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame})

See above.

@kindex n
@cindex magit-blame-next-chunk
@item @kbd{n} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-next-chunk})

This command moves to the next chunk.

@kindex N
@cindex magit-blame-next-chunk-same-commit
@item @kbd{N} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-next-chunk-same-commit})

This command moves to the next chunk from the same commit.

@kindex p
@cindex magit-blame-previous-chunk
@item @kbd{p} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-previous-chunk})

This command moves to the previous chunk.

@kindex P
@cindex magit-blame-previous-chunk-same-commit
@item @kbd{P} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-previous-chunk-same-commit})

This command moves to the previous chunk from the same commit.

@kindex q
@cindex magit-blame-quit
@item @kbd{q} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-quit})

This command turns off Magit-Blame mode.  If the buffer was created
during a recursive blame, then it also kills the buffer.

@kindex M-w
@cindex magit-blame-copy-hash
@item @kbd{M-w} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-copy-hash})

This command saves the hash of the current chunk's commit to the
kill ring.

When the region is active, the command saves the region's content
instead of the hash, like @code{kill-ring-save} would.

@kindex c
@cindex magit-blame-cycle-style
@item @kbd{c} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-cycle-style})

This command changes how blame information is visualized in the
current buffer by cycling through the styles specified using the
option @code{magit-blame-styles}.
@end table

Blaming is also controlled using the following options.

@defopt magit-blame-styles

This option defines a list of styles used to visualize blame
information.  For now see its doc-string to learn more.
@end defopt

@defopt magit-blame-echo-style

This option specifies the blame visualization style used by the
command @code{magit-blame-echo}.  This must be a symbol that is used as the
identifier for one of the styles defined in @code{magit-blame-styles}.
@end defopt

@defopt magit-blame-time-format

This option specifies the format string used to display times when
showing blame information.
@end defopt

@defopt magit-blame-read-only

This option controls whether blaming a buffer also makes temporarily
read-only.
@end defopt

@defopt magit-blame-disable-modes

This option lists incompatible minor-modes that should be disabled
temporarily when a buffer contains blame information.  They are
enabled again when the buffer no longer shows blame information.
@end defopt

@defopt magit-blame-goto-chunk-hook

This hook is run when moving between chunks.
@end defopt

@node Manipulating
@chapter Manipulating

@menu
* Creating Repository::
* Cloning Repository::
* Staging and Unstaging::
* Applying::
* Committing::
* Branching::
* Merging::
* Resolving Conflicts::
* Rebasing::
* Cherry Picking::
* Resetting::
* Stashing::
@end menu

@node Creating Repository
@section Creating Repository

@table @asis
@kindex M-x magit-init
@cindex magit-init
@item @kbd{M-x magit-init} @tie{}@tie{}@tie{}@tie{}(@code{magit-init})

This command initializes a repository and then shows the status
buffer for the new repository.

If the directory is below an existing repository, then the user has
to confirm that a new one should be created inside.  If the
directory is the root of the existing repository, then the user has
to confirm that it should be reinitialized.
@end table

@node Cloning Repository
@section Cloning Repository

To clone a remote or local repository use @code{C}, which is bound to the
command @code{magit-clone}.  This command either act as a transient prefix
command, which binds several infix arguments and suffix commands, or
it can invoke @code{git clone} directly, depending on whether a prefix
argument is used and on the value of @code{magit-clone-always-transient}.

@defopt magit-clone-always-transient

This option controls whether the command @code{magit-clone} always acts as
a transient prefix command, regardless of whether a prefix argument
is used or not.  If @code{t}, then that command always acts as a transient
prefix.  If @code{nil}, then a prefix argument has to be used for it to act
as a transient.
@end defopt

@table @asis
@kindex C
@cindex magit-clone
@item @kbd{C} @tie{}@tie{}@tie{}@tie{}(@code{magit-clone})

This command either acts as a transient prefix command as described
above or does the same thing as @code{transient-clone-regular} as described
below.

If it acts as a transient prefix, then it binds the following suffix
commands and several infix arguments.

@kindex C C
@cindex magit-clone-regular
@item @kbd{C C} @tie{}@tie{}@tie{}@tie{}(@code{magit-clone-regular})

This command creates a regular clone of an existing repository.
The repository and the target directory are read from the user.

@kindex C s
@cindex magit-clone-shallow
@item @kbd{C s} @tie{}@tie{}@tie{}@tie{}(@code{magit-clone-shallow})

This command creates a shallow clone of an existing repository.
The repository and the target directory are read from the user.
By default the depth of the cloned history is a single commit,
but with a prefix argument the depth is read from the user.

@kindex C b
@cindex magit-clone-bare
@item @kbd{C b} @tie{}@tie{}@tie{}@tie{}(@code{magit-clone-bare})

This command creates a bare clone of an existing repository.
The repository and the target directory are read from the user.

@kindex C m
@cindex magit-clone-mirror
@item @kbd{C m} @tie{}@tie{}@tie{}@tie{}(@code{magit-clone-mirror})

This command creates a mirror of an existing repository.
The repository and the target directory are read from the user.
@end table

The following suffixes are disabled by default. See
@ref{Enabling and Disabling Suffixes,,,transient,} for how to enable them.

@table @asis
@kindex C d
@cindex magit-clone-shallow-since
@item @kbd{C d} @tie{}@tie{}@tie{}@tie{}(@code{magit-clone-shallow-since})

This command creates a shallow clone of an existing repository.
Only commits that were committed after a date are cloned, which
is read from the user.  The repository and the target directory
are also read from the user.

@kindex C e
@cindex magit-clone-shallow-exclude
@item @kbd{C e} @tie{}@tie{}@tie{}@tie{}(@code{magit-clone-shallow-exclude})

This command creates a shallow clone of an existing repository.
This reads a branch or tag from the user.  Commits that are
reachable from that are not cloned.  The repository and the target
directory are also read from the user.

@end table

@defopt magit-clone-set-remote-head

This option controls whether cloning causes the reference
@code{refs/remotes/<remote>/HEAD} to be created in the clone.  The default
is to delete the reference after running @code{git clone}, which insists on
creating it.  This is because the reference has not been found to be
particularly useful as it is not automatically updated when the @code{HEAD}
of the remote changes.  Setting this option to @code{t} preserves Git's
default behavior of creating the reference.
@end defopt

@defopt magit-clone-set-remote.pushDefault

This option controls whether the value of the Git variable
@code{remote.pushDefault} is set after cloning.

@itemize
@item
If @code{t}, then it is always set without asking.

@item
If @code{ask}, then the users are asked every time they clone a
repository.

@item
If @code{nil}, then it is never set.
@end itemize
@end defopt

@defopt magit-clone-default-directory

This option control the default directory name used when reading the
destination for a cloning operation.

@itemize
@item
If @code{nil} (the default), then the value of @code{default-directory} is used.

@item
If a directory, then that is used.

@item
If a function, then that is called with the remote url as the only
argument and the returned value is used.
@end itemize
@end defopt

@defopt magit-clone-name-alist

This option maps regular expressions, which match repository names,
to repository urls, making it possible for users to enter short
names instead of urls when cloning repositories.

Each element has the form @code{(REGEXP HOSTNAME USER)}.  When the user
enters a name when a cloning command asks for a name or url, then
that is looked up in this list.  The first element whose REGEXP
matches is used.

The format specified by option @code{magit-clone-url-format} is used to
turn the name into an url, using HOSTNAME and the repository name.
If the provided name contains a slash, then that is used.  Otherwise
if the name omits the owner of the repository, then the default user
specified in the matched entry is used.

If USER contains a dot, then it is treated as a Git variable and the
value of that is used as the username.  Otherwise it is used as the
username itself.
@end defopt

@defopt magit-clone-url-format

The format specified by this option is used when turning repository
names into urls. @code{%h} is the hostname and @code{%n} is the repository name,
including the name of the owner.
@end defopt

@node Staging and Unstaging
@section Staging and Unstaging

Like Git, Magit can of course stage and unstage complete files.
Unlike Git, it also allows users to gracefully un-/stage
individual hunks and even just part of a hunk.  To stage individual
hunks and parts of hunks using Git directly, one has to use the very
modal and rather clumsy interface of a @code{git add --interactive} session.

With Magit, on the other hand, one can un-/stage individual hunks by
just moving point into the respective section inside a diff displayed
in the status buffer or a separate diff buffer and typing @code{s} or @code{u}.  To
operate on just parts of a hunk, mark the changes that should be
un-/staged using the region and then press the same key that would be
used to un-/stage.  To stage multiple files or hunks at once use a
region that starts inside the heading of such a section and ends
inside the heading of a sibling section of the same type.

Besides staging and unstaging, Magit also provides several other
"apply variants" that can also operate on a file, multiple files at
once, a hunk, multiple hunks at once, and on parts of a hunk.  These
apply variants are described in the next section.

You can also use Ediff to stage and unstage.  See @ref{Ediffing}.

@table @asis
@kindex s
@cindex magit-stage
@item @kbd{s} @tie{}@tie{}@tie{}@tie{}(@code{magit-stage})

Add the change at point to the staging area.

With a prefix argument and an untracked file (or files) at point,
stage the file but not its content.  This makes it possible to stage
only a subset of the new file's changes.

@kindex S
@cindex magit-stage-modified
@item @kbd{S} @tie{}@tie{}@tie{}@tie{}(@code{magit-stage-modified})

Stage all changes to files modified in the worktree.  Stage all new
content of tracked files and remove tracked files that no longer
exist in the working tree from the index also.  With a prefix
argument also stage previously untracked (but not ignored) files.

@kindex u
@cindex magit-unstage
@item @kbd{u} @tie{}@tie{}@tie{}@tie{}(@code{magit-unstage})

Remove the change at point from the staging area.

Only staged changes can be unstaged.  But by default this command
performs an action that is somewhat similar to unstaging, when it is
called on a committed change: it reverses the change in the index
but not in the working tree.

@kindex U
@cindex magit-unstage-all
@item @kbd{U} @tie{}@tie{}@tie{}@tie{}(@code{magit-unstage-all})

Remove all changes from the staging area.

@end table

@defopt magit-unstage-committed

This option controls whether @code{magit-unstage} "unstages" committed
changes by reversing them in the index but not the working tree.
The alternative is to raise an error.
@end defopt

@table @asis
@kindex M-x magit-reverse-in-index
@cindex magit-reverse-in-index
@item @kbd{M-x magit-reverse-in-index} @tie{}@tie{}@tie{}@tie{}(@code{magit-reverse-in-index})

This command reverses the committed change at point in the index but
not the working tree.  By default no key is bound directly to this
command, but it is indirectly called when @code{u} (@code{magit-unstage}) is
pressed on a committed change.

This allows extracting a change from @code{HEAD}, while leaving it in the
working tree, so that it can later be committed using a separate
commit.  A typical workflow would be:

@itemize
@item
Optionally make sure that there are no uncommitted changes.

@item
Visit the @code{HEAD} commit and navigate to the change that should
not have been included in that commit.

@item
Type @code{u} (@code{magit-unstage}) to reverse it in the index.
This assumes that @code{magit-unstage-committed-changes} is non-nil.

@item
Type @code{c e} to extend @code{HEAD} with the staged changes,
including those that were already staged before.

@item
Optionally stage the remaining changes using @code{s} or @code{S} and then
type @code{c c} to create a new commit.
@end itemize

@kindex M-x magit-reset-index
@cindex magit-reset-index
@item @kbd{M-x magit-reset-index} @tie{}@tie{}@tie{}@tie{}(@code{magit-reset-index})

Reset the index to some commit.  The commit is read from the user
and defaults to the commit at point.  If there is no commit at
point, then it defaults to @code{HEAD}.
@end table

@menu
* Staging from File-Visiting Buffers::
@end menu

@node Staging from File-Visiting Buffers
@subsection Staging from File-Visiting Buffers

Fine-grained un-/staging has to be done from the status or a diff
buffer, but it's also possible to un-/stage all changes made to the
file visited in the current buffer right from inside that buffer.

@table @asis
@kindex M-x magit-stage-file
@cindex magit-stage-file
@item @kbd{M-x magit-stage-file} @tie{}@tie{}@tie{}@tie{}(@code{magit-stage-file})

When invoked inside a file-visiting buffer, then stage all changes
to that file.  In a Magit buffer, stage the file at point if any.
Otherwise prompt for a file to be staged.  With a prefix argument
always prompt the user for a file, even in a file-visiting buffer or
when there is a file section at point.

@kindex M-x magit-unstage-file
@cindex magit-unstage-file
@item @kbd{M-x magit-unstage-file} @tie{}@tie{}@tie{}@tie{}(@code{magit-unstage-file})

When invoked inside a file-visiting buffer, then unstage all changes
to that file.  In a Magit buffer, unstage the file at point if any.
Otherwise prompt for a file to be unstaged.  With a prefix argument
always prompt the user for a file, even in a file-visiting buffer or
when there is a file section at point.
@end table

@node Applying
@section Applying

Magit provides several "apply variants": stage, unstage, discard,
reverse, and "regular apply".  At least when operating on a hunk they
are all implemented using @code{git apply}, which is why they are called
"apply variants".

@itemize
@item
Stage.  Apply a change from the working tree to the index.  The change
also remains in the working tree.


@item
Unstage.  Remove a change from the index.  The change remains in the
working tree.


@item
Discard.  On a staged change, remove it from the working tree and the
index.  On an unstaged change, remove it from the working tree only.


@item
Reverse.  Reverse a change in the working tree.  Both committed and
staged changes can be reversed.  Unstaged changes cannot be
reversed.  Discard them instead.


@item
Apply.  Apply a change to the working tree.  Both committed and staged
changes can be applied.  Unstaged changes cannot be applied - as
they already have been applied.
@end itemize

The previous section described the staging and unstaging commands.
What follows are the commands which implement the remaining apply
variants.

@table @asis
@kindex a
@cindex magit-apply
@item @kbd{a} @tie{}@tie{}@tie{}@tie{}(@code{magit-apply})

Apply the change at point to the working tree.

With a prefix argument fallback to a 3-way merge.  Doing so causes
the change to be applied to the index as well.

@kindex k
@cindex magit-discard
@item @kbd{k} @tie{}@tie{}@tie{}@tie{}(@code{magit-discard})

Remove the change at point from the working tree.

@kindex v
@cindex magit-reverse
@item @kbd{v} @tie{}@tie{}@tie{}@tie{}(@code{magit-reverse})

Reverse the change at point in the working tree.

With a prefix argument fallback to a 3-way merge.  Doing so causes
the change to be applied to the index as well.
@end table

With a prefix argument all apply variants attempt a 3-way merge when
appropriate (i.e. when @code{git apply} is used internally).

@node Committing
@section Committing

When the user initiates a commit, Magit calls @code{git commit} without any
arguments, so Git has to get it from the user.  It creates the file
@code{.git/COMMIT_EDITMSG} and then opens that file in an editor.  Magit
arranges for that editor to be the Emacsclient.  Once the user
finishes the editing session, the Emacsclient exits and Git creates the
commit using the file's content as message.

@menu
* Initiating a Commit::
* Editing Commit Messages::
@end menu

@node Initiating a Commit
@subsection Initiating a Commit

Also see 
@ifinfo
@ref{git-commit,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-commit">git-commit(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-commit(1) manpage.
@end iftex

@table @asis
@kindex c
@cindex magit-commit
@item @kbd{c} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.

@kindex c c
@cindex magit-commit-create
@item @kbd{c c} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-create})

Create a new commit on @code{HEAD}.  With a prefix argument amend to the
commit at @code{HEAD} instead.

@kindex c a
@cindex magit-commit-amend
@item @kbd{c a} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-amend})

Amend the last commit.

@kindex c e
@cindex magit-commit-extend
@item @kbd{c e} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-extend})

Amend the last commit, without editing the message.  With a prefix
argument keep the committer date, otherwise change it.  The option
@code{magit-commit-extend-override-date} can be used to inverse the meaning
of the prefix argument.

Non-interactively respect the optional OVERRIDE-DATE argument and
ignore the option.

@kindex c w
@cindex magit-commit-reword
@item @kbd{c w} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-reword})

Reword the last commit, ignoring staged changes.  With a prefix
argument keep the committer date, otherwise change it.  The option
@code{magit-commit-reword-override-date} can be used to inverse the meaning
of the prefix argument.

Non-interactively respect the optional OVERRIDE-DATE argument and
ignore the option.

@kindex c f
@cindex magit-commit-fixup
@item @kbd{c f} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-fixup})

Create a fixup commit.

With a prefix argument the target commit has to be confirmed.
Otherwise the commit at point may be used without confirmation
depending on the value of option @code{magit-commit-squash-confirm}.

@kindex c F
@cindex magit-commit-instant-fixup
@item @kbd{c F} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-instant-fixup})

Create a fixup commit and instantly rebase.

@kindex c s
@cindex magit-commit-squash
@item @kbd{c s} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-squash})

Create a squash commit, without editing the squash message.

With a prefix argument the target commit has to be confirmed.
Otherwise the commit at point may be used without confirmation
depending on the value of option @code{magit-commit-squash-confirm}.

@kindex c S
@cindex magit-commit-instant-squash
@item @kbd{c S} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-instant-squash})

Create a squash commit and instantly rebase.

@kindex c A
@cindex magit-commit-augment
@item @kbd{c A} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-augment})

Create a squash commit, editing the squash message.

With a prefix argument the target commit has to be confirmed.
Otherwise the commit at point may be used without confirmation
depending on the value of option @code{magit-commit-squash-confirm}.

@end table

@defopt magit-commit-ask-to-stage

Whether to ask to stage all unstaged changes when committing and nothing is
staged.
@end defopt

@defopt magit-commit-extend-override-date

Whether using @code{magit-commit-extend} changes the committer date.
@end defopt

@defopt magit-commit-reword-override-date

Whether using @code{magit-commit-reword} changes the committer date.
@end defopt

@defopt magit-commit-squash-confirm

Whether the commit targeted by squash and fixup has to be confirmed.
When non-nil then the commit at point (if any) is used as default
choice.  Otherwise it has to be confirmed.  This option only affects
@code{magit-commit-squash} and @code{magit-commit-fixup}.  The "instant" variants
always require confirmation because making an error while using
those is harder to recover from.
@end defopt

@node Editing Commit Messages
@subsection Editing Commit Messages

After initiating a commit as described in the previous section, two new
buffers appear.  One shows the changes that are about to be committed,
while the other is used to write the message.

Commit messages are edited in an edit session - in the background @code{git}
is waiting for the editor, in our case @code{emacsclient}, to save the commit
message in a file (in most cases @code{.git/COMMIT_EDITMSG}) and then return.
If the editor returns with a non-zero exit status then @code{git} does not
create the commit.  So the most important commands are those for
finishing and aborting the commit.

@table @asis
@kindex C-c C-c
@cindex with-editor-finish
@item @kbd{C-c C-c} @tie{}@tie{}@tie{}@tie{}(@code{with-editor-finish})

Finish the current editing session by returning with exit code 0.
Git then creates the commit using the message it finds in the file.

@kindex C-c C-k
@cindex with-editor-cancel
@item @kbd{C-c C-k} @tie{}@tie{}@tie{}@tie{}(@code{with-editor-cancel})

Cancel the current editing session by returning with exit code 1.
Git then cancels the commit, but leaves the file untouched.
@end table

In addition to being used by @code{git commit}, messages may also be stored
in a ring that persists until Emacs is closed.  By default the message
is stored at the beginning and the end of an edit session (regardless
of whether the session is finished successfully or was canceled).  It
is sometimes useful to bring back messages from that ring.

@table @asis
@kindex C-c M-s
@cindex git-commit-save-message
@item @kbd{C-c M-s} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-save-message})

Save the current buffer content to the commit message ring.

@kindex M-p
@cindex git-commit-prev-message
@item @kbd{M-p} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-prev-message})

Cycle backward through the commit message ring, after saving the
current message to the ring.  With a numeric prefix ARG, go back
ARG comments.

@kindex M-n
@cindex git-commit-next-message
@item @kbd{M-n} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-next-message})

Cycle forward through the commit message ring, after saving the
current message to the ring.  With a numeric prefix ARG, go back
ARG comments.
@end table

By default the diff for the changes that are about to be committed are
automatically shown when invoking the commit.  To prevent that, remove
@code{magit-commit-diff} from @code{server-switch-hook}.

When amending to an existing commit it may be useful to show either
the changes that are about to be added to that commit or to show those
changes alongside those that have already been committed.

@table @asis
@kindex C-c C-d
@cindex magit-diff-while-committing
@item @kbd{C-c C-d} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-while-committing})

While committing, show the changes that are about to be committed.
While amending, invoking the command again toggles between showing
just the new changes or all the changes that will be committed.
@end table

@menu
* Using the Revision Stack::
* Commit Pseudo Headers::
* Commit Mode and Hooks::
* Commit Message Conventions::
@end menu

@node Using the Revision Stack
@unnumberedsubsubsec Using the Revision Stack

@table @asis
@kindex C-c C-w
@cindex magit-pop-revision-stack
@item @kbd{C-c C-w} @tie{}@tie{}@tie{}@tie{}(@code{magit-pop-revision-stack})

This command inserts a representation of a revision into the current
buffer.  It can be used inside buffers used to write commit messages
but also in other buffers such as buffers used to edit emails or
ChangeLog files.

By default this command pops the revision which was last added to
the @code{magit-revision-stack} and inserts it into the current buffer
according to @code{magit-pop-revision-stack-format}.  Revisions can be put
on the stack using @code{magit-copy-section-value} and
@code{magit-copy-buffer-revision}.

If the stack is empty or with a prefix argument it instead reads a
revision in the minibuffer.  By using the minibuffer history this
allows selecting an item which was popped earlier or to insert an
arbitrary reference or revision without first pushing it onto the
stack.

When reading the revision from the minibuffer, then it might not
be possible to guess the correct repository.  When this command
is called inside a repository (e.g. while composing a commit
message), then that repository is used.  Otherwise (e.g. while
composing an email) then the repository recorded for the top
element of the stack is used (even though we insert another
revision).  If not called inside a repository and with an empty
stack, or with two prefix arguments, then read the repository in
the minibuffer too.

@end table

@defopt magit-pop-revision-stack-format

This option controls how the command @code{magit-pop-revision-stack}
inserts a revision into the current buffer.

The entries on the stack have the format @code{(HASH TOPLEVEL)} and this
option has the format @code{(POINT-FORMAT EOB-FORMAT INDEX-REGEXP)}, all
of which may be nil or a string (though either one of EOB-FORMAT
or POINT-FORMAT should be a string, and if INDEX-REGEXP is
non-nil, then the two formats should be too).

First INDEX-REGEXP is used to find the previously inserted entry,
by searching backward from point.  The first submatch must match
the index number.  That number is incremented by one, and becomes
the index number of the entry to be inserted.  If you don't want
to number the inserted revisions, then use nil for INDEX-REGEXP@.

If INDEX-REGEXP is non-nil then both POINT-FORMAT and EOB-FORMAT
should contain \"%N\", which is replaced with the number that was
determined in the previous step.

Both formats, if non-nil and after removing %N, are then expanded
using @code{git show --format=FORMAT ...} inside TOPLEVEL@.

The expansion of POINT-FORMAT is inserted at point, and the
expansion of EOB-FORMAT is inserted at the end of the buffer (if the
buffer ends with a comment, then it is inserted right before that).
@end defopt

@node Commit Pseudo Headers
@unnumberedsubsubsec Commit Pseudo Headers

Some projects use pseudo headers in commit messages.  Magit colorizes
such headers and provides some commands to insert such headers.

@defopt git-commit-known-pseudo-headers

A list of Git pseudo headers to be highlighted.
@end defopt

@table @asis
@kindex C-c C-i
@cindex git-commit-insert-pseudo-header
@item @kbd{C-c C-i} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-insert-pseudo-header})

Insert a commit message pseudo header.

@kindex C-c C-a
@cindex git-commit-ack
@item @kbd{C-c C-a} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-ack})

Insert a header acknowledging that you have looked at the commit.

@kindex C-c C-r
@cindex git-commit-review
@item @kbd{C-c C-r} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-review})

Insert a header acknowledging that you have reviewed the commit.

@kindex C-c C-s
@cindex git-commit-signoff
@item @kbd{C-c C-s} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-signoff})

Insert a header to sign off the commit.

@kindex C-c C-t
@cindex git-commit-test
@item @kbd{C-c C-t} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-test})

Insert a header acknowledging that you have tested the commit.

@kindex C-c C-o
@cindex git-commit-cc
@item @kbd{C-c C-o} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-cc})

Insert a header mentioning someone who might be interested.

@kindex C-c C-p
@cindex git-commit-reported
@item @kbd{C-c C-p} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-reported})

Insert a header mentioning the person who reported the issue being
fixed by the commit.

@kindex C-c M-i
@cindex git-commit-suggested
@item @kbd{C-c M-i} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-suggested})

Insert a header mentioning the person who suggested the change.
@end table

@node Commit Mode and Hooks
@unnumberedsubsubsec Commit Mode and Hooks

@code{git-commit-mode} is a minor mode that is only used to establish certain
key bindings.  This makes it possible to use an arbitrary major mode
in buffers used to edit commit messages.  It is even possible to use
different major modes in different repositories, which is useful when
different projects impose different commit message conventions.

@defopt git-commit-major-mode

The value of this option is the major mode used to edit Git commit
messages.
@end defopt

Because @code{git-commit-mode} is a minor mode, we don't use its mode hook
to setup the buffer, except for the key bindings.  All other setup
happens in the function @code{git-commit-setup}, which among other things runs
the hook @code{git-commit-setup-hook}.


@defopt git-commit-setup-hook

Hook run at the end of @code{git-commit-setup}.
@end defopt

@noindent
The following functions are suitable for this hook:

@defun git-commit-save-message

Save the current buffer content to the commit message ring.
@end defun

@defun git-commit-setup-changelog-support

After this function is called, ChangeLog entries are treated as
paragraphs.
@end defun

@defun git-commit-turn-on-auto-fill

Turn on @code{auto-fill-mode} and set @code{fill-column} to the value of
@code{git-commit-fill-column}.
@end defun

@defun git-commit-turn-on-flyspell

Turn on Flyspell mode.  Also prevent comments from being checked and
finally check current non-comment text.
@end defun

@defun git-commit-propertize-diff

Propertize the diff shown inside the commit message buffer.  Git
inserts such diffs into the commit message template when the
@code{--verbose} argument is used.  @code{magit-commit} by default does not offer
that argument because the diff that is shown in a separate buffer is
more useful.  But some users disagree, which is why this function
exists.
@end defun

@defun bug-reference-mode

Hyperlink bug references in the buffer.
@end defun

@defun with-editor-usage-message

Show usage information in the echo area.
@end defun

@defopt git-commit-setup-hook

Hook run after the user finished writing a commit message.

This hook is only run after pressing @code{C-c C-c} in a buffer used to
edit a commit message.  If a commit is created without the user
typing a message into a buffer, then this hook is not run.

This hook is not run until the new commit has been created.  If
doing so takes Git longer than one second, then this hook isn't run
at all.  For certain commands such as @code{magit-rebase-continue} this
hook is never run because doing so would lead to a race condition.

This hook is only run if @code{magit} is available.

Also see @code{magit-post-commit-hook}.
@end defopt

@node Commit Message Conventions
@unnumberedsubsubsec Commit Message Conventions

Git-Commit highlights certain violations of commonly accepted commit
message conventions.  Certain violations even cause Git-Commit to ask
you to confirm that you really want to do that.  This nagging can of
course be turned off, but the result of doing that usually is that
instead of some code it's now the human who is reviewing your commits
who has to waste some time telling you to fix your commits.

@defopt git-commit-summary-max-length

The intended maximal length of the summary line of commit messages.
Characters beyond this column are colorized to indicate that this
preference has been violated.
@end defopt

@defopt git-commit-fill-column

Column beyond which automatic line-wrapping should happen in commit
message buffers.
@end defopt

@defopt git-commit-finish-query-functions

List of functions called to query before performing commit.

The commit message buffer is current while the functions are called.
If any of them returns nil, then the commit is not performed and the
buffer is not killed.  The user should then fix the issue and try
again.

The functions are called with one argument.  If it is non-nil then
that indicates that the user used a prefix argument to force
finishing the session despite issues.  Functions should usually
honor this wish and return non-nil.

By default the only member is @code{git-commit-check-style-conventions}.
@end defopt

@defun git-commit-check-style-conventions

This function checks for violations of certain basic style
conventions.  For each violation it asks users if they want to
proceed anyway.
@end defun

@defopt git-commit-style-convention-checks

This option controls what conventions the function by the same name
tries to enforce.  The value is a list of self-explanatory symbols
identifying certain conventions; @code{non-empty-second-line} and
@code{overlong-summary-line}.
@end defopt

@node Branching
@section Branching

@menu
* The Two Remotes::
* Branch Commands::
* Branch Git Variables::
* Auxiliary Branch Commands::
@end menu

@node The Two Remotes
@subsection The Two Remotes

The upstream branch of some local branch is the branch into which the
commits on that local branch should eventually be merged, usually
something like @code{origin/master}.  For the @code{master} branch itself the
upstream branch and the branch it is being pushed to, are usually the
same remote branch.  But for a feature branch the upstream branch and
the branch it is being pushed to should differ.

The commits on feature branches too should @emph{eventually} end up in a
remote branch such as @code{origin/master} or @code{origin/maint}.  Such a branch
should therefore be used as the upstream.  But feature branches
shouldn't be pushed directly to such branches.  Instead a feature
branch @code{my-feature} is usually pushed to @code{my-fork/my-feature} or if you
are a contributor @code{origin/my-feature}.  After the new feature has been
reviewed, the maintainer merges the feature into @code{master}.  And finally
@code{master} (not @code{my-feature} itself) is pushed to @code{origin/master}.

But new features seldom are perfect on the first try, and so feature
branches usually have to be reviewed, improved, and re-pushed several
times.  Pushing should therefore be easy to do, and for that reason
many Git users have concluded that it is best to use the remote branch
to which the local feature branch is being pushed as its upstream.

But luckily Git has long ago gained support for a push-remote which
can be configured separately from the upstream branch, using the
variables @code{branch.<name>.pushRemote} and @code{remote.pushDefault}.  So we no
longer have to choose which of the two remotes should be used as "the
remote".

Each of the fetching, pulling, and pushing transient commands features
three suffix commands that act on the current branch and some other
branch.  Of these, @code{p} is bound to a command which acts on the
push-remote, @code{u} is bound to a command which acts on the upstream, and @code{e}
is bound to a command which acts on any other branch.  The status
buffer shows unpushed and unpulled commits for both the push-remote
and the upstream.

It's fairly simple to configure these two remotes.  The values of all
the variables that are related to fetching, pulling, and pushing (as
well as some other branch-related variables) can be inspected and
changed using the command @code{magit-branch-configure}, which is available
from many transient prefix commands that deal with branches.  It is
also possible to set the push-remote or upstream while pushing (see
@ref{Pushing}).

@node Branch Commands
@subsection Branch Commands

The transient prefix command @code{magit-branch} is used to create and
checkout branches, and to make changes to existing branches.  It is
not used to fetch, pull, merge, rebase, or push branches, i.e. this
command deals with branches themselves, not with the commits reachable
from them.  Those features are available from separate transient
command.

@table @asis
@kindex b
@cindex magit-branch
@item @kbd{b} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch})

This transient prefix command binds the following suffix commands
and displays them in a temporary buffer until a suffix is invoked.

By default it also binds and displays the values of some
branch-related Git variables and allows changing their values.

@end table

@defopt magit-branch-direct-configure

This option controls whether the transient command @code{magit-branch} can
be used directly change the values Git variables.  This defaults to
@code{t} (to avoid changing key bindings).  When set to @code{nil}, then no
variables are displayed by that transient command, and its suffix
command @code{magit-branch-configure} has to be used instead to view and
change branch related variables.
@end defopt

@table @asis
@kindex b C
@cindex magit-branch-configure
@item @kbd{b C} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-configure})
@kindex f C
@cindex magit-branch-configure
@item @kbd{f C} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-configure})
@kindex F C
@cindex magit-branch-configure
@item @kbd{F C} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-configure})
@kindex P C
@cindex magit-branch-configure
@item @kbd{P C} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-configure})

This transient prefix command binds commands that set the value of
branch-related variables and displays them in a temporary buffer
until the transient is exited.

With a prefix argument, this command always prompts for a branch.

Without a prefix argument this depends on whether it was invoked as
a suffix of @code{magit-branch} and on the @code{magit-branch-direct-configure}
option.  If @code{magit-branch} already displays the variables for the
current branch, then it isn't useful to invoke another transient
that displays them for the same branch.  In that case this command
prompts for a branch.
@end table

The variables are described in @ref{Branch Git Variables}.

@table @asis
@kindex b b
@cindex magit-checkout
@item @kbd{b b} @tie{}@tie{}@tie{}@tie{}(@code{magit-checkout})

Checkout a revision read in the minibuffer and defaulting to the
branch or arbitrary revision at point.  If the revision is a local
branch then that becomes the current branch.  If it is something
else then @code{HEAD} becomes detached.  Checkout fails if the working tree
or the staging area contain changes.

@kindex b n
@cindex magit-branch-create
@item @kbd{b n} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-create})

Create a new branch.  The user is asked for a branch or arbitrary
revision to use as the starting point of the new branch.  When a
branch name is provided, then that becomes the upstream branch of
the new branch.  The name of the new branch is also read in the
minibuffer.

Also see option @code{magit-branch-prefer-remote-upstream}.

@kindex b c
@cindex magit-branch-and-checkout
@item @kbd{b c} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-and-checkout})

This command creates a new branch like @code{magit-branch}, but then also
checks it out.

Also see option @code{magit-branch-prefer-remote-upstream}.

@kindex b l
@cindex magit-branch-checkout
@item @kbd{b l} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-checkout})

This command checks out an existing or new local branch.  It reads a
branch name from the user offering all local branches and a subset
of remote branches as candidates.  Remote branches for which a local
branch by the same name exists are omitted from the list of
candidates.  The user can also enter a completely new branch name.

@itemize
@item
If the user selects an existing local branch, then that is checked
out.


@item
If the user selects a remote branch, then it creates and checks
out a new local branch with the same name, and configures the
selected remote branch as the push target.


@item
If the user enters a new branch name, then it creates and checks
that out, after also reading the starting-point from the user.
@end itemize

In the latter two cases the upstream is also set.  Whether it is set
to the chosen starting point or something else depends on the value
of @code{magit-branch-adjust-remote-upstream-alist}.

@kindex b s
@cindex magit-branch-spinoff
@item @kbd{b s} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-spinoff})

This command creates and checks out a new branch starting at and
tracking the current branch.  That branch in turn is reset to the
last commit it shares with its upstream.  If the current branch has
no upstream or no unpushed commits, then the new branch is created
anyway and the previously current branch is not touched.

This is useful to create a feature branch after work has already
began on the old branch (likely but not necessarily "master").

If the current branch is a member of the value of option
@code{magit-branch-prefer-remote-upstream} (which see), then the current
branch will be used as the starting point as usual, but the upstream
of the starting-point may be used as the upstream of the new branch,
instead of the starting-point itself.

If optional FROM is non-nil, then the source branch is reset
to @code{FROM~}, instead of to the last commit it shares with its
upstream.  Interactively, FROM is only ever non-nil, if the
region selects some commits, and among those commits, FROM is
the commit that is the fewest commits ahead of the source
branch.

The commit at the other end of the selection actually does not
matter, all commits between FROM and @code{HEAD} are moved to the new
branch.  If FROM is not reachable from @code{HEAD} or is reachable from the
source branch's upstream, then an error is raised.

@kindex b S
@cindex magit-branch-spinout
@item @kbd{b S} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-spinout})

This command behaves like @code{magit-branch-spinoff}, except that it does
not change the current branch.  If there are any uncommitted changes,
then it behaves exactly like @code{magit-branch-spinoff}.

@kindex b x
@cindex magit-branch-reset
@item @kbd{b x} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-reset})

This command resets a branch, defaulting to the branch at point, to
the tip of another branch or any other commit.

When the branch being reset is the current branch, then a hard reset
is performed.  If there are any uncommitted changes, then the user
has to confirm the reset because those changes would be lost.

This is useful when you have started work on a feature branch but
realize it's all crap and want to start over.

When resetting to another branch and a prefix argument is used, then
the target branch is set as the upstream of the branch that is being
reset.

@kindex b k
@cindex magit-branch-delete
@item @kbd{b k} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-delete})

Delete one or multiple branches.  If the region marks multiple
branches, then offer to delete those.  Otherwise, prompt for a single
branch to be deleted, defaulting to the branch at point.

@kindex b r
@cindex magit-branch-rename
@item @kbd{b r} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-rename})

Rename a branch.  The branch and the new name are read in the
minibuffer.  With prefix argument the branch is renamed even if that
name conflicts with an existing branch.

@end table

@defopt magit-branch-read-upstream-first

When creating a branch, whether to read the upstream branch before
the name of the branch that is to be created.  The default is @code{nil},
and I recommend you leave it at that.
@end defopt

@defopt magit-branch-prefer-remote-upstream

This option specifies whether remote upstreams are favored over
local upstreams when creating new branches.

When a new branch is created, then the branch, commit, or stash at
point is suggested as the starting point of the new branch, or if
there is no such revision at point the current branch.  In either
case the user may choose another starting point.

If the chosen starting point is a branch, then it may also be set
as the upstream of the new branch, depending on the value of the
Git variable `branch.autoSetupMerge'.  By default this is done
for remote branches, but not for local branches.

You might prefer to always use some remote branch as upstream.
If the chosen starting point is (1) a local branch, (2) whose
name matches a member of the value of this option, (3) the
upstream of that local branch is a remote branch with the same
name, and (4) that remote branch can be fast-forwarded to the
local branch, then the chosen branch is used as starting point,
but its own upstream is used as the upstream of the new branch.

Members of this option's value are treated as branch names that
have to match exactly unless they contain a character that makes
them invalid as a branch name.  Recommended characters to use
to trigger interpretation as a regexp are "*" and "^".  Some
other characters which you might expect to be invalid, actually
are not, e.g. ".+$" are all perfectly valid.  More precisely,
if @code{git check-ref-format --branch STRING} exits with a non-zero
status, then treat STRING as a regexp.

Assuming the chosen branch matches these conditions you would end
up with with e.g.:

@example
feature --upstream--> origin/master
@end example

instead of

@example
feature --upstream--> master --upstream--> origin/master
@end example

Which you prefer is a matter of personal preference.  If you do
prefer the former, then you should add branches such as @code{master},
@code{next}, and @code{maint} to the value of this options.
@end defopt

@defopt magit-branch-adjust-remote-upstream-alist

The value of this option is an alist of branches to be used as
the upstream when branching a remote branch.

When creating a local branch from an ephemeral branch located on a
remote, e.g. a feature or hotfix branch, then that remote branch
should usually not be used as the upstream branch, since the
push-remote already allows accessing it and having both the upstream
and the push-remote reference the same related branch would be
wasteful.  Instead a branch like "maint" or "master" should be used
as the upstream.

This option allows specifying the branch that should be used as the
upstream when branching certain remote branches.  The value is an
alist of the form @code{((UPSTREAM . RULE)...)}.  The first matching
element is used, the following elements are ignored.

UPSTREAM is the branch to be used as the upstream for branches
specified by RULE@.  It can be a local or a remote branch.

RULE can either be a regular expression, matching branches whose
upstream should be the one specified by UPSTREAM@.  Or it can be a
list of the only branches that should @strong{not} use UPSTREAM; all other
branches will.  Matching is done after stripping the remote part of
the name of the branch that is being branched from.

If you use a finite set of non-ephemeral branches across all your
repositories, then you might use something like:

@lisp
(("origin/master" "master" "next" "maint"))
@end lisp

Or if the names of all your ephemeral branches contain a slash,
at least in some repositories, then a good value could be:

@lisp
(("origin/master" . "/"))
@end lisp

Of course you can also fine-tune:

@lisp
(("origin/maint" . "\\`hotfix/")
 ("origin/master" . "\\`feature/"))
@end lisp
@end defopt

@cindex magit-branch-orphan
@deffn Command magit-branch-orphan

This command creates and checks out a new orphan branch with
contents from a given revision.
@end deffn

@cindex magit-branch-or-checkout
@deffn Command magit-branch-or-checkout

This command is a hybrid between @code{magit-checkout} and
@code{magit-branch-and-checkout} and is intended as a replacement for the
former in @code{magit-branch}.

It first asks the user for an existing branch or revision.  If the
user input actually can be resolved as a branch or revision, then it
checks that out, just like @code{magit-checkout} would.

Otherwise it creates and checks out a new branch using the input as
its name.  Before doing so it reads the starting-point for the new
branch.  This is similar to what @code{magit-branch-and-checkout} does.

To use this command instead of @code{magit-checkout} add this to your init
file:

@lisp
(transient-replace-suffix 'magit-branch 'magit-checkout
  '("b" "dwim" magit-branch-or-checkout))
@end lisp
@end deffn

@node Branch Git Variables
@subsection Branch Git Variables

These variables can be set from the transient prefix command
@code{magit-branch-configure}.  By default they can also be set from
@code{magit-branch}.  See @ref{Branch Commands}.

@defvar branch.NAME.merge

Together with @code{branch.NAME.remote} this variable defines the upstream
branch of the local branch named NAME@.  The value of this variable
is the full reference of the upstream @emph{branch}.
@end defvar

@defvar branch.NAME.remote

Together with @code{branch.NAME.merge} this variable defines the upstream
branch of the local branch named NAME@.  The value of this variable
is the name of the upstream @emph{remote}.
@end defvar

@defvar branch.NAME.rebase

This variable controls whether pulling into the branch named NAME is
done by rebasing or by merging the fetched branch.

@itemize
@item
When @code{true} then pulling is done by rebasing.

@item
When @code{false} then pulling is done by merging.

@item
When undefined then the value of @code{pull.rebase} is used.  The default
of that variable is @code{false}.
@end itemize
@end defvar

@defvar branch.NAME.pushRemote

This variable specifies the remote that the branch named NAME is
usually pushed to.  The value has to be the name of an existing
remote.

It is not possible to specify the name of @emph{branch} to push the local
branch to.  The name of the remote branch is always the same as the
name of the local branch.

If this variable is undefined but @code{remote.pushDefault} is defined,
then the value of the latter is used.  By default @code{remote.pushDefault}
is undefined.
@end defvar

@defvar branch.NAME.description

This variable can be used to describe the branch named NAME@.  That
description is used e.g. when turning the branch into a series of
patches.
@end defvar

The following variables specify defaults which are used if the above
branch-specific variables are not set.

@defvar pull.rebase

This variable specifies whether pulling is done by rebasing or by
merging.  It can be overwritten using @code{branch.NAME.rebase}.

@itemize
@item
When @code{true} then pulling is done by rebasing.

@item
When @code{false} (the default) then pulling is done by merging.
@end itemize

Since it is never a good idea to merge the upstream branch into a
feature or hotfix branch and most branches are such branches, you
should consider setting this to @code{true}, and @code{branch.master.rebase} to
@code{false}.
@end defvar

@defvar remote.pushDefault

This variable specifies what remote the local branches are usually
pushed to.  This can be overwritten per branch using
@code{branch.NAME.pushRemote}.
@end defvar

The following variables are used during the creation of a branch and
control whether the various branch-specific variables are
automatically set at this time.

@defvar branch.autoSetupMerge

This variable specifies under what circumstances creating a branch
NAME should result in the variables @code{branch.NAME.merge} and
@code{branch.NAME.remote} being set according to the starting point used to
create the branch.  If the starting point isn't a branch, then these
variables are never set.

@itemize
@item
When @code{always} then the variables are set regardless of whether the
starting point is a local or a remote branch.

@item
When @code{true} (the default) then the variables are set when the starting
point is a remote branch, but not when it is a local branch.

@item
When @code{false} then the variables are never set.
@end itemize
@end defvar

@defvar branch.autoSetupRebase

This variable specifies whether creating a branch NAME should result
in the variable @code{branch.NAME.rebase} being set to @code{true}.

@itemize
@item
When @code{always} then the variable is set regardless of whether the
starting point is a local or a remote branch.

@item
When @code{local} then the variable are set when the starting point is a
local branch, but not when it is a remote branch.

@item
When @code{remote} then the variable are set when the starting point is a
remote branch, but not when it is a local branch.

@item
When @code{never} (the default) then the variable is never set.
@end itemize
@end defvar

Note that the respective commands always change the repository-local
values.  If you want to change the global value, which is used when
the local value is undefined, then you have to do so on the command
line, e.g.:

@example
git config --global remote.autoSetupMerge always
@end example

For more information about these variables you should also see

@ifinfo
@ref{git-config,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-config">git-config(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-config(1) manpage.
@end iftex
 Also see 
@ifinfo
@ref{git-branch,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-branch">git-branch(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-branch(1) manpage.
@end iftex
, 
@ifinfo
@ref{git-checkout,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-checkout">git-checkout(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-checkout(1) manpage.
@end iftex
 and @ref{Pushing}.

@defopt magit-prefer-remote-upstream

This option controls whether commands that read a branch from the
user and then set it as the upstream branch, offer a local or a
remote branch as default completion candidate, when they have the
choice.

This affects all commands that use @code{magit-read-upstream-branch} or
@code{magit-read-starting-point}, which includes all commands that change
the upstream and many which create new branches.
@end defopt

@node Auxiliary Branch Commands
@subsection Auxiliary Branch Commands

These commands are not available from the transient @code{magit-branch} by
default.

@cindex magit-branch-shelve
@deffn Command magit-branch-shelve

This command shelves a branch.  This is done by deleting the branch,
and creating a new reference "refs/shelved/BRANCH-NAME" pointing at
the same commit as the branch pointed at.  If the deleted branch had
a reflog, then that is preserved as the reflog of the new reference.

This is useful if you want to move a branch out of sight, but are
not ready to completely discard it yet.
@end deffn

@cindex magit-branch-unshelve
@deffn Command magit-branch-unshelve

This command unshelves a branch that was previously shelved using
@code{magit-branch-shelve}.  This is done by deleting the reference
"refs/shelved/BRANCH-NAME" and creating a branch "BRANCH-NAME"
pointing at the same commit as the deleted reference pointed at.
If the deleted reference had a reflog, then that is restored as
the reflog of the branch.
@end deffn

@node Merging
@section Merging

Also see 
@ifinfo
@ref{git-merge,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-merge">git-merge(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-merge(1) manpage.
@end iftex
  For information on how to resolve
merge conflicts see the next section.

@table @asis
@kindex m
@cindex magit-merge
@item @kbd{m} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.
@end table

When no merge is in progress, then the transient features the
following suffix commands.

@table @asis
@kindex m m
@cindex magit-merge-plain
@item @kbd{m m} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge-plain})

This command merges another branch or an arbitrary revision into the
current branch.  The branch or revision to be merged is read in the
minibuffer and defaults to the branch at point.

Unless there are conflicts or a prefix argument is used, then the
resulting merge commit uses a generic commit message, and the user
does not get a chance to inspect or change it before the commit is
created.  With a prefix argument this does not actually create the
merge commit, which makes it possible to inspect how conflicts were
resolved and to adjust the commit message.

@kindex m e
@cindex magit-merge-editmsg
@item @kbd{m e} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge-editmsg})

This command merges another branch or an arbitrary revision into the
current branch and opens a commit message buffer, so that the user
can make adjustments.  The commit is not actually created until the
user finishes with @code{C-c C-c}.

@kindex m n
@cindex magit-merge-nocommit
@item @kbd{m n} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge-nocommit})

This command merges another branch or an arbitrary revision into the
current branch, but does not actually create the merge commit.  The
user can then further adjust the merge, even when automatic conflict
resolution succeeded and/or adjust the commit message.

@kindex m a
@cindex magit-merge-absorb
@item @kbd{m a} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge-absorb})

This command merges another local branch into the current branch and
then removes the former.

Before the source branch is merged, it is first force pushed to its
push-remote, provided the respective remote branch already exists.
This ensures that the respective pull-request (if any) won't get
stuck on some obsolete version of the commits that are being merged.
Finally, if @code{magit-branch-pull-request} was used to create the merged
branch, then the respective remote branch is also removed.

@kindex m i
@cindex magit-merge-into
@item @kbd{m i} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge-into})

This command merges the current branch into another local branch and
then removes the former.  The latter becomes the new current branch.

Before the source branch is merged, it is first force pushed to its
push-remote, provided the respective remote branch already exists.
This ensures that the respective pull-request (if any) won't get
stuck on some obsolete version of the commits that are being merged.
Finally, if @code{magit-branch-pull-request} was used to create the merged
branch, then the respective remote branch is also removed.

@kindex m s
@cindex magit-merge-squash
@item @kbd{m s} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge-squash})

This command squashes the changes introduced by another branch or an
arbitrary revision into the current branch.  This only applies the
changes made by the squashed commits.  No information is preserved
that would allow creating an actual merge commit.  Instead of this
command you should probably use a command from the apply transient.

@kindex m p
@cindex magit-merge-preview
@item @kbd{m p} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge-preview})

This command shows a preview of merging another branch or an
arbitrary revision into the current branch.
@end table

When a merge is in progress, then the transient instead features the
following suffix commands.

@table @asis
@kindex m m
@cindex magit-merge
@item @kbd{m m} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge})

After the user resolved conflicts, this command proceeds with the
merge.  If some conflicts weren't resolved, then this command fails.

@kindex m a
@cindex magit-merge-abort
@item @kbd{m a} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge-abort})

This command aborts the current merge operation.
@end table

@node Resolving Conflicts
@section Resolving Conflicts

When merging branches (or otherwise combining or changing history)
conflicts can occur.  If you edited two completely different parts of
the same file in two branches and then merge one of these branches
into the other, then Git can resolve that on its own, but if you edit
the same area of a file, then a human is required to decide how the
two versions, or "sides of the conflict", are to be combined into one.

Here we can only provide a brief introduction to the subject and point
you toward some tools that can help.  If you are new to this, then
please also consult Git's own documentation as well as other
resources.

If a file has conflicts and Git cannot resolve them by itself, then it
puts both versions into the affected file along with special markers
whose purpose is to denote the boundaries of the unresolved part of
the file and between the different versions.  These boundary lines
begin with the strings consisting of six times the same character, one
of @code{<}, @code{|}, @code{=} and @code{>} and are followed by information about the source of
the respective versions, e.g.:

@example
<<<<<<< HEAD
Take the blue pill.
=======
Take the red pill.
>>>>>>> feature
@end example

In this case you have chosen to take the red pill on one branch and on
another you picked the blue pill.  Now that you are merging these two
diverging branches, Git cannot possibly know which pill you want to
take.

To resolve that conflict you have to create a version of the affected
area of the file by keeping only one of the sides, possibly by editing
it in order to bring in the changes from the other side, remove the
other versions as well as the markers, and then stage the result.  A
possible resolution might be:

@example
Take both pills.
@end example

Often it is useful to see not only the two sides of the conflict but
also the "original" version from before the same area of the file was
modified twice on different branches.  Instruct Git to insert that
version as well by running this command once:

@example
git config --global merge.conflictStyle diff3
@end example

The above conflict might then have looked like this:

@example
<<<<<<< HEAD
Take the blue pill.
||||||| merged common ancestors
Take either the blue or the red pill, but not both.
=======
Take the red pill.
>>>>>>> feature
@end example

If that were the case, then the above conflict resolution would not
have been correct, which demonstrates why seeing the original version
alongside the conflicting versions can be useful.

You can perform the conflict resolution completely by hand, but Emacs
also provides some packages that help in the process: Smerge, Ediff
(@ref{Top,,,ediff,}), and Emerge (@ref{Emerge,,,emacs,}).  Magit does not provide
its own tools for conflict resolution, but it does make using Smerge
and Ediff more convenient.  (Ediff supersedes Emerge, so you probably
don't want to use the latter anyway.)

In the Magit status buffer, files with unresolved conflicts are listed
in the "Unstaged changes" and/or "Staged changes" sections.  They are
prefixed with the word "unmerged", which in this context essentially
is a synonym for "unresolved".

Pressing @code{RET} while point is on such a file section shows a buffer
visiting that file, turns on @code{smerge-mode} in that buffer, and places
point inside the first area with conflicts.  You should then resolve
that conflict using regular edit commands and/or Smerge commands.

Unfortunately Smerge does not have a manual, but you can get a list of
commands and binding @code{C-c ^ C-h} and press @code{RET} while point is on a
command name to read its documentation.

Normally you would edit one version and then tell Smerge to keep only
that version.  Use @code{C-c ^ m} (@code{smerge-keep-mine}) to keep the @code{HEAD}
version or @code{C-c ^ o} (@code{smerge-keep-other}) to keep the version that
follows "|||||||".  Then use @code{C-c ^ n} to move to the next conflicting
area in the same file.  Once you are done resolving conflicts, return
to the Magit status buffer.  The file should now be shown as
"modified", no longer as "unmerged", because Smerge automatically
stages the file when you save the buffer after resolving the last
conflict.

Alternatively you could use Ediff, which uses separate buffers for the
different versions of the file.  To resolve conflicts in a file using
Ediff press @code{e} while point is on such a file in the status buffer.

Ediff can be used for other purposes as well.  For more information on
how to enter Ediff from Magit, see @ref{Ediffing}.  Explaining how to use
Ediff is beyond the scope of this manual, instead see @ref{Top,,,ediff,}.

If you are unsure whether you should Smerge or Ediff, then use the
former.  It is much easier to understand and use, and except for
truly complex conflicts, the latter is usually overkill.

@node Rebasing
@section Rebasing

Also see 
@ifinfo
@ref{git-rebase,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-rebase">git-rebase(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-rebase(1) manpage.
@end iftex
  For information on how to resolve
conflicts that occur during rebases see the preceding section.

@table @asis
@kindex r
@cindex magit-rebase
@item @kbd{r} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.
@end table

When no rebase is in progress, then the transient features the
following suffix commands.

Using one of these commands @emph{starts} a rebase sequence.  Git might then
stop somewhere along the way, either because you told it to do so, or
because applying a commit failed due to a conflict.  When that
happens, then the status buffer shows information about the rebase
sequence which is in progress in a section similar to a log section.
See @ref{Information About In-Progress Rebase}.

For information about the upstream and the push-remote, see @ref{The Two Remotes}.

@table @asis
@kindex r p
@cindex magit-rebase-onto-pushremote
@item @kbd{r p} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-onto-pushremote})

This command rebases the current branch onto its push-remote.

With a prefix argument or when the push-remote is either not
configured or unusable, then let the user first configure the
push-remote.

@kindex r u
@cindex magit-rebase-onto-upstream
@item @kbd{r u} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-onto-upstream})

This command rebases the current branch onto its upstream branch.

With a prefix argument or when the upstream is either not
configured or unusable, then let the user first configure
the upstream.

@kindex r e
@cindex magit-rebase-branch
@item @kbd{r e} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-branch})

This command rebases the current branch onto a branch read in the
minibuffer.  All commits that are reachable from head but not from
the selected branch TARGET are being rebased.

@kindex r s
@cindex magit-rebase-subset
@item @kbd{r s} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-subset})

This command starts a non-interactive rebase sequence to transfer
commits from START to @code{HEAD} onto NEWBASE@.  START has to be selected
from a list of recent commits.
@end table

By default Magit uses the @code{--autostash} argument, which causes
uncommitted changes to be stored in a stash before the rebase begins.
These changes are restored after the rebase completes and if possible
the stash is removed.  If the stash does not apply cleanly, then the
stash is not removed.  In case something goes wrong when resolving
the conflicts, this allows you to start over.

Even though one of the actions is dedicated to interactive rebases,
the transient also features the infix argument @code{--interactive}.  This
can be used to turn one of the other, non-interactive rebase variants
into an interactive rebase.

For example if you want to clean up a feature branch and at the same
time rebase it onto @code{master}, then you could use @code{r-iu}.  But we recommend
that you instead do that in two steps.  First use @code{ri} to cleanup the
feature branch, and then in a second step @code{ru} to rebase it onto @code{master}.
That way if things turn out to be more complicated than you thought
and/or you make a mistake and have to start over, then you only have
to redo half the work.

Explicitly enabling @code{--interactive} won't have an effect on the
following commands as they always use that argument anyway, even if it
is not enabled in the transient.

@table @asis
@kindex r i
@cindex magit-rebase-interactive
@item @kbd{r i} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-interactive})

This command starts an interactive rebase sequence.

@kindex r f
@cindex magit-rebase-autosquash
@item @kbd{r f} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-autosquash})

This command combines squash and fixup commits with their intended
targets.

@kindex r m
@cindex magit-rebase-edit-commit
@item @kbd{r m} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-edit-commit})

This command starts an interactive rebase sequence that lets the
user edit a single older commit.

@kindex r w
@cindex magit-rebase-reword-commit
@item @kbd{r w} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-reword-commit})

This command starts an interactive rebase sequence that lets the
user reword a single older commit.

@kindex r k
@cindex magit-rebase-remove-commit
@item @kbd{r k} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-remove-commit})

This command removes a single older commit using rebase.
@end table

When a rebase is in progress, then the transient instead features
the following suffix commands.

@table @asis
@kindex r r
@cindex magit-rebase-continue
@item @kbd{r r} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-continue})

This command restart the current rebasing operation.

In some cases this pops up a commit message buffer for you do edit.
With a prefix argument the old message is reused as-is.

@kindex r s
@cindex magit-rebase-skip
@item @kbd{r s} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-skip})

This command skips the current commit and restarts the current
rebase operation.

@kindex r e
@cindex magit-rebase-edit
@item @kbd{r e} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-edit})

This command lets the user edit the todo list of the current rebase
operation.

@kindex r a
@cindex magit-rebase-abort
@item @kbd{r a} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-abort})

This command aborts the current rebase operation, restoring the
original branch.
@end table

@menu
* Editing Rebase Sequences::
* Information About In-Progress Rebase::
@end menu

@node Editing Rebase Sequences
@subsection Editing Rebase Sequences

@table @asis
@kindex C-c C-c
@cindex with-editor-finish
@item @kbd{C-c C-c} @tie{}@tie{}@tie{}@tie{}(@code{with-editor-finish})

Finish the current editing session by returning with exit code 0.
Git then uses the rebase instructions it finds in the file.

@kindex C-c C-k
@cindex with-editor-cancel
@item @kbd{C-c C-k} @tie{}@tie{}@tie{}@tie{}(@code{with-editor-cancel})

Cancel the current editing session by returning with exit code 1.
Git then forgoes starting the rebase sequence.

@kindex RET
@cindex git-rebase-show-commit
@item @kbd{RET} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-show-commit})

Show the commit on the current line in another buffer and select
that buffer.

@kindex SPC
@cindex git-rebase-show-or-scroll-up
@item @kbd{SPC} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-show-or-scroll-up})

Show the commit on the current line in another buffer without
selecting that buffer.  If the revision buffer is already visible in
another window of the current frame, then instead scroll that window
up.

@kindex DEL
@cindex git-rebase-show-or-scroll-down
@item @kbd{DEL} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-show-or-scroll-down})

Show the commit on the current line in another buffer without
selecting that buffer.  If the revision buffer is already visible in
another window of the current frame, then instead scroll that window
down.

@kindex p
@cindex git-rebase-backward-line
@item @kbd{p} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-backward-line})

Move to previous line.

@kindex n
@cindex forward-line
@item @kbd{n} @tie{}@tie{}@tie{}@tie{}(@code{forward-line})

Move to next line.

@kindex M-p
@cindex git-rebase-move-line-up
@item @kbd{M-p} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-move-line-up})

Move the current commit (or command) up.

@kindex M-n
@cindex git-rebase-move-line-down
@item @kbd{M-n} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-move-line-down})

Move the current commit (or command) down.

@kindex r
@cindex git-rebase-reword
@item @kbd{r} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-reword})

Edit message of commit on current line.

@kindex e
@cindex git-rebase-edit
@item @kbd{e} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-edit})

Stop at the commit on the current line.

@kindex s
@cindex git-rebase-squash
@item @kbd{s} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-squash})

Meld commit on current line into previous commit, and edit message.

@kindex f
@cindex git-rebase-fixup
@item @kbd{f} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-fixup})

Meld commit on current line into previous commit, discarding the
current commit's message.

@kindex k
@cindex git-rebase-kill-line
@item @kbd{k} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-kill-line})

Kill the current action line.

@kindex c
@cindex git-rebase-pick
@item @kbd{c} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-pick})

Use commit on current line.

@kindex x
@cindex git-rebase-exec
@item @kbd{x} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-exec})

Insert a shell command to be run after the proceeding commit.

If there already is such a command on the current line, then edit
that instead.  With a prefix argument insert a new command even when
there already is one on the current line.  With empty input remove
the command on the current line, if any.

@kindex b
@cindex git-rebase-break
@item @kbd{b} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-break})

Insert a break action before the current line, instructing Git to
return control to the user.

@kindex y
@cindex git-rebase-insert
@item @kbd{y} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-insert})

Read an arbitrary commit and insert it below current line.

@kindex C-x u
@cindex git-rebase-undo
@item @kbd{C-x u} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-undo})

Undo some previous changes.  Like @code{undo} but works in read-only
buffers.

@end table

@defopt git-rebase-auto-advance

Whether to move to next line after changing a line.
@end defopt

@defopt git-rebase-show-instructions

Whether to show usage instructions inside the rebase buffer.
@end defopt

@defopt git-rebase-confirm-cancel

Whether confirmation is required to cancel.
@end defopt

When a rebase is performed with the @code{--rebase-merges} option, the
sequence will include a few other types of actions and the following
commands become relevant.

@table @asis
@kindex l
@cindex git-rebase-label
@item @kbd{l} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-label})

This commands inserts a label action or edits the one at point.

@kindex t
@cindex git-rebase-reset
@item @kbd{t} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-reset})

This command inserts a reset action or edits the one at point.  The
prompt will offer the labels that are currently present in the
buffer.

@kindex MM
@cindex git-rebase-merge
@item @kbd{MM} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-merge})

The command inserts a merge action or edits the one at point.  The
prompt will offer the labels that are currently present in the
buffer.  Specifying a message to reuse via @code{-c} or @code{-C} is not
supported; an editor will always be invoked for the merge.

@kindex Mt
@cindex git-rebase-merge-toggle-editmsg
@item @kbd{Mt} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-merge-toggle-editmsg})

This command toggles between the @code{-C} and @code{-c} options of the merge
action at point.  These options both specify a commit whose message
should be reused.  The lower-case variant instructs Git to invoke
the editor when creating the merge, allowing the user to edit the
message.
@end table

@node Information About In-Progress Rebase
@subsection Information About In-Progress Rebase

While a rebase sequence is in progress, the status buffer features a
section that lists the commits that have already been applied as well
as the commits that still have to be applied.

The commits are split in two halves.  When rebase stops at a commit,
either because the user has to deal with a conflict or because s/he
explicitly requested that rebase stops at that commit, then point is
placed on the commit that separates the two groups, i.e. on @code{HEAD}.  The
commits above it have not been applied yet, while the @code{HEAD} and the
commits below it have already been applied.  In between these two
groups of applied and yet-to-be applied commits, there sometimes is a
commit which has been dropped.

Each commit is prefixed with a word and these words are additionally
shown in different colors to indicate the status of the commits.

The following colors are used:

@itemize
@item
Yellow commits have not been applied yet.


@item
Gray commits have already been applied.


@item
The blue commit is the @code{HEAD} commit.


@item
The green commit is the commit the rebase sequence stopped at.  If
this is the same commit as @code{HEAD} (e.g. because you haven't done
anything yet after rebase stopped at the commit, then this commit is
shown in blue, not green).  There can only be a green @strong{and} a blue
commit at the same time, if you create one or more new commits after
rebase stops at a commit.


@item
Red commits have been dropped.  They are shown for reference only,
e.g. to make it easier to diff.
@end itemize

Of course these colors are subject to the color-theme in use.

The following words are used:

@itemize
@item
Commits prefixed with @code{pick}, @code{reword}, @code{edit}, @code{squash}, and @code{fixup} have not
been applied yet.  These words have the same meaning here as they do
in the buffer used to edit the rebase sequence.  See @ref{Editing Rebase Sequences}.  When the @code{--rebase-merges} option was specified,
@code{reset}, @code{label}, and @code{merge} lines may also be present.


@item
Commits prefixed with @code{done} and @code{onto} have already been applied.
It is possible for such a commit to be the @code{HEAD}, in which case it
is blue.  Otherwise it is grey.

@itemize
@item
The commit prefixed with @code{onto} is the commit on top of which all
the other commits are being re-applied.  This commit itself did
not have to be re-applied, it is the commit rebase did rewind to
before starting to re-apply other commits.


@item
Commits prefixed with @code{done} have already been re-applied.  This
includes commits that have been re-applied but also new commits
that you have created during the rebase.
@end itemize


@item
All other commits, those not prefixed with any of the above words,
are in some way related to the commit at which rebase stopped.

To determine whether a commit is related to the stopped-at commit
their hashes, trees and patch-ids @footnote{The patch-id is a hash of the @emph{changes} introduced by a
commit.  It differs from the hash of the commit itself, which is a
hash of the result of applying that change (i.e. the resulting trees
and blobs) as well as author and committer information, the commit
message, and the hashes of the parents of the commit.  The patch-id
hash on the other hand is created only from the added and removed
lines, even line numbers and whitespace changes are ignored when
calculating this hash.  The patch-ids of two commits can be used to
answer the question "Do these commits make the same change?".} are being compared.
The commit message is not used for this purpose.

Generally speaking commits that are related to the stopped-at commit
can have any of the used colors, though not all color/word
combinations are possible.

Words used for stopped-at commits are:

@itemize
@item
When a commit is prefixed with @code{void}, then that indicates that
Magit knows for sure that all the changes in that commit have been
applied using several new commits.  This commit is no longer
reachable from @code{HEAD}, and it also isn't one of the commits that
will be applied when resuming the session.


@item
When a commit is prefixed with @code{join}, then that indicates that the
rebase sequence stopped at that commit due to a conflict - you now
have to join (merge) the changes with what has already been
applied.  In a sense this is the commit rebase stopped at, but
while its effect is already in the index and in the worktree (with
conflict markers), the commit itself has not actually been applied
yet (it isn't the @code{HEAD}).  So it is shown in yellow, like the other
commits that still have to be applied.


@item
When a commit is prefixed with @code{stop} or a @emph{blue} or @emph{green} @code{same}, then
that indicates that rebase stopped at this commit, that it is
still applied or has been applied again, and that at least its
patch-id is unchanged.

@itemize
@item
When a commit is prefixed with @code{stop}, then that indicates that
rebase stopped at that commit because you requested that
earlier, and its patch-id is unchanged.  It might even still be
the exact same commit.


@item
When a commit is prefixed with a @emph{blue} or @emph{green} @code{same}, then that
indicates that while its tree or hash changed, its patch-id did
not.  If it is blue, then it is the @code{HEAD} commit (as always for
blue).  When it is green, then it no longer is @code{HEAD} because
other commit have been created since (but before continuing the
rebase).
@end itemize


@item
When a commit is prefixed with @code{goal}, a @emph{yellow} @code{same,} or @code{work}, then
that indicates that rebase applied that commit but that you then
reset @code{HEAD} to an earlier commit (likely to split it up into
multiple commits), and that there are some uncommitted changes
remaining which likely (but not necessarily) originate from that
commit.

@itemize
@item
When a commit is prefixed with @code{goal}, then that indicates that it
is still possible to create a new commit with the exact same
tree (the "goal") without manually editing any files, by
committing the index, or by staging all changes and then
committing that.  This is the case when the original tree still
exists in the index or worktree in untainted form.


@item
When a commit is prefixed with a yellow @code{same}, then that
indicates that it is no longer possible to create a commit with
the exact same tree, but that it is still possible to create a
commit with the same patch-id.  This would be the case if you
created a new commit with other changes, but the changes from
the original commit still exist in the index or working tree in
untainted form.


@item
When a commit is prefixed with @code{work}, then that indicates that
you reset @code{HEAD} to an earlier commit, and that there are some
staged and/or unstaged changes (likely, but not necessarily)
originating from that commit.  However it is no longer possible
to create a new commit with the same tree or at least the same
patch-id because you have already made other changes.
@end itemize


@item
When a commit is prefixed with @code{poof} or @code{gone}, then that indicates
that rebase applied that commit but that you then reset @code{HEAD} to an
earlier commit (likely to split it up into multiple commits), and
that there are no uncommitted changes.

@itemize
@item
When a commit is prefixed with @code{poof}, then that indicates that it
is no longer reachable from @code{HEAD}, but that it has been replaced
with one or more commits, which together have the exact same
effect.


@item
When a commit is prefixed with @code{gone}, then that indicates that it
is no longer reachable from @code{HEAD} and that we also cannot
determine whether its changes are still in effect in one or more
new commits.  They might be, but if so, then there must also be
other changes which makes it impossible to know for sure.
@end itemize
@end itemize
@end itemize

Do not worry if you do not fully understand the above.  That's okay,
you will acquire a good enough understanding through practice.

For other sequence operations such as cherry-picking, a similar section
is displayed, but they lack some of the features described above, due
to limitations in the git commands used to implement them.  Most
importantly these sequences only support "picking" a commit but not
other actions such as "rewording", and they do not keep track of the
commits which have already been applied.

@node Cherry Picking
@section Cherry Picking

Also see 
@ifinfo
@ref{git-cherry-pick,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-cherry-pick">git-cherry-pick(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-cherry-pick(1) manpage.
@end iftex

@table @asis
@kindex A
@cindex magit-cherry-pick
@item @kbd{A} @tie{}@tie{}@tie{}@tie{}(@code{magit-cherry-pick})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.
@end table

When no cherry-pick or revert is in progress, then the transient
features the following suffix commands.

@table @asis
@kindex A A
@cindex magit-cherry-copy
@item @kbd{A A} @tie{}@tie{}@tie{}@tie{}(@code{magit-cherry-copy})

This command copies COMMITS from another branch onto the current
branch.  If the region selects multiple commits, then those are
copied, without prompting.  Otherwise the user is prompted for a
commit or range, defaulting to the commit at point.

@kindex A a
@cindex magit-cherry-apply
@item @kbd{A a} @tie{}@tie{}@tie{}@tie{}(@code{magit-cherry-apply})

This command applies the changes in COMMITS from another branch onto
the current branch.  If the region selects multiple commits, then
those are used, without prompting.  Otherwise the user is prompted
for a commit or range, defaulting to the commit at point.

This command also has a top-level binding, which can be invoked
without using the transient by typing @code{a} at the top-level.
@end table

The following commands not only apply some commits to some branch, but
also remove them from some other branch.  The removal is performed
using either @code{git-update-ref} or if necessary @code{git-rebase}.  Both applying
commits as well as removing them using @code{git-rebase} can lead to
conflicts.  If that happens, then these commands abort and you not
only have to resolve the conflicts but also finish the process the
same way you would have to if these commands didn't exist at all.

@table @asis
@kindex A h
@cindex magit-cherry-harvest
@item @kbd{A h} @tie{}@tie{}@tie{}@tie{}(@code{magit-cherry-harvest})

This command moves the selected COMMITS that must be located on
another BRANCH onto the current branch instead, removing them from
the former.  When this command succeeds, then the same branch is
current as before.

Applying the commits on the current branch or removing them from the
other branch can lead to conflicts.  When that happens, then this
command stops and you have to resolve the conflicts and then finish
the process manually.

@kindex A d
@cindex magit-cherry-donate
@item @kbd{A d} @tie{}@tie{}@tie{}@tie{}(@code{magit-cherry-donate})

This command moves the selected COMMITS from the current branch onto
another existing BRANCH, removing them from the former.  When this
command succeeds, then the same branch is current as before.

Applying the commits on the other branch or removing them from the
current branch can lead to conflicts.  When that happens, then this
command stops and you have to resolve the conflicts and then finish
the process manually.

@kindex A n
@cindex magit-cherry-spinout
@item @kbd{A n} @tie{}@tie{}@tie{}@tie{}(@code{magit-cherry-spinout})

This command moves the selected COMMITS from the current branch onto
a new branch BRANCH, removing them from the former.  When this
command succeeds, then the same branch is current as before.

Applying the commits on the other branch or removing them from the
current branch can lead to conflicts.  When that happens, then this
command stops and you have to resolve the conflicts and then finish
the process manually.

@kindex A s
@cindex magit-cherry-spinoff
@item @kbd{A s} @tie{}@tie{}@tie{}@tie{}(@code{magit-cherry-spinoff})

This command moves the selected COMMITS from the current branch onto
a new branch BRANCH, removing them from the former.  When this
command succeeds, then the new branch is checked out.

Applying the commits on the other branch or removing them from the
current branch can lead to conflicts.  When that happens, then this
command stops and you have to resolve the conflicts and then finish
the process manually.
@end table

When a cherry-pick or revert is in progress, then the transient
instead features the following suffix commands.

@table @asis
@kindex A A
@cindex magit-sequence-continue
@item @kbd{A A} @tie{}@tie{}@tie{}@tie{}(@code{magit-sequence-continue})

Resume the current cherry-pick or revert sequence.

@kindex A s
@cindex magit-sequence-skip
@item @kbd{A s} @tie{}@tie{}@tie{}@tie{}(@code{magit-sequence-skip})

Skip the stopped at commit during a cherry-pick or revert sequence.

@kindex A a
@cindex magit-sequence-abort
@item @kbd{A a} @tie{}@tie{}@tie{}@tie{}(@code{magit-sequence-abort})

Abort the current cherry-pick or revert sequence.  This discards all
changes made since the sequence started.
@end table

@menu
* Reverting::
@end menu

@node Reverting
@subsection Reverting

@table @asis
@kindex V
@cindex magit-revert
@item @kbd{V} @tie{}@tie{}@tie{}@tie{}(@code{magit-revert})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.
@end table

When no cherry-pick or revert is in progress, then the transient
features the following suffix commands.

@table @asis
@kindex V V
@cindex magit-revert-and-commit
@item @kbd{V V} @tie{}@tie{}@tie{}@tie{}(@code{magit-revert-and-commit})

Revert a commit by creating a new commit.  Prompt for a commit,
defaulting to the commit at point.  If the region selects multiple
commits, then revert all of them, without prompting.

@kindex V v
@cindex magit-revert-no-commit
@item @kbd{V v} @tie{}@tie{}@tie{}@tie{}(@code{magit-revert-no-commit})

Revert a commit by applying it in reverse to the working tree.
Prompt for a commit, defaulting to the commit at point.  If the
region selects multiple commits, then revert all of them, without
prompting.
@end table

When a cherry-pick or revert is in progress, then the transient
instead features the following suffix commands.

@table @asis
@kindex V A
@cindex magit-sequence-continue
@item @kbd{V A} @tie{}@tie{}@tie{}@tie{}(@code{magit-sequence-continue})

Resume the current cherry-pick or revert sequence.

@kindex V s
@cindex magit-sequence-skip
@item @kbd{V s} @tie{}@tie{}@tie{}@tie{}(@code{magit-sequence-skip})

Skip the stopped at commit during a cherry-pick or revert sequence.

@kindex V a
@cindex magit-sequence-abort
@item @kbd{V a} @tie{}@tie{}@tie{}@tie{}(@code{magit-sequence-abort})

Abort the current cherry-pick or revert sequence.  This discards all
changes made since the sequence started.
@end table

@node Resetting
@section Resetting

Also see 
@ifinfo
@ref{git-reset,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-reset">git-reset(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-reset(1) manpage.
@end iftex

@table @asis
@kindex x
@cindex magit-reset-quickly
@item @kbd{x} @tie{}@tie{}@tie{}@tie{}(@code{magit-reset-quickly})

Reset the @code{HEAD} and index to some commit read from the user and
defaulting to the commit at point, and possibly also reset the
working tree.  With a prefix argument reset the working tree
otherwise don't.

@kindex X m
@cindex magit-reset-mixed
@item @kbd{X m} @tie{}@tie{}@tie{}@tie{}(@code{magit-reset-mixed})

Reset the @code{HEAD} and index to some commit read from the user and
defaulting to the commit at point.  The working tree is kept as-is.

@kindex X s
@cindex magit-reset-soft
@item @kbd{X s} @tie{}@tie{}@tie{}@tie{}(@code{magit-reset-soft})

Reset the @code{HEAD} to some commit read from the user and defaulting
to the commit at point.  The index and the working tree are kept
as-is.

@kindex X h
@cindex magit-reset-hard
@item @kbd{X h} @tie{}@tie{}@tie{}@tie{}(@code{magit-reset-hard})

Reset the @code{HEAD}, index, and working tree to some commit read from the
user and defaulting to the commit at point.

@kindex X i
@cindex magit-reset-index
@item @kbd{X i} @tie{}@tie{}@tie{}@tie{}(@code{magit-reset-index})

Reset the index to some commit read from the user and defaulting to
the commit at point.  Keep the @code{HEAD} and working tree as-is, so if
the commit refers to the @code{HEAD}, then this effectively unstages all
changes.

@kindex X w
@cindex magit-reset-worktree
@item @kbd{X w} @tie{}@tie{}@tie{}@tie{}(@code{magit-reset-worktree})

Reset the working tree to some commit read from the user and
defaulting to the commit at point.  Keep the @code{HEAD} and index as-is.

@kindex X f
@cindex magit-file-checkout
@item @kbd{X f} @tie{}@tie{}@tie{}@tie{}(@code{magit-file-checkout})

Update file in the working tree and index to the contents from a
revision.  Both the revision and file are read from the user.
@end table

@node Stashing
@section Stashing

Also see 
@ifinfo
@ref{git-stash,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-stash">git-stash(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-stash(1) manpage.
@end iftex

@table @asis
@kindex z
@cindex magit-stash
@item @kbd{z} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.

@kindex z z
@cindex magit-stash-both
@item @kbd{z z} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-both})

Create a stash of the index and working tree.  Untracked files are
included according to infix arguments.  One prefix argument is
equivalent to @code{--include-untracked} while two prefix arguments are
equivalent to @code{--all}.

@kindex z i
@cindex magit-stash-index
@item @kbd{z i} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-index})

Create a stash of the index only.  Unstaged and untracked changes
are not stashed.

@kindex z w
@cindex magit-stash-worktree
@item @kbd{z w} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-worktree})

Create a stash of unstaged changes in the working tree.  Untracked
files are included according to infix arguments.  One prefix
argument is equivalent to @code{--include-untracked} while two prefix
arguments are equivalent to @code{--all}.

@kindex z x
@cindex magit-stash-keep-index
@item @kbd{z x} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-keep-index})

Create a stash of the index and working tree, keeping index intact.
Untracked files are included according to infix arguments.  One
prefix argument is equivalent to @code{--include-untracked} while two
prefix arguments are equivalent to @code{--all}.

@kindex z Z
@cindex magit-snapshot-both
@item @kbd{z Z} @tie{}@tie{}@tie{}@tie{}(@code{magit-snapshot-both})

Create a snapshot of the index and working tree.  Untracked files
are included according to infix arguments.  One prefix argument is
equivalent to @code{--include-untracked} while two prefix arguments are
equivalent to @code{--all}.

@kindex z I
@cindex magit-snapshot-index
@item @kbd{z I} @tie{}@tie{}@tie{}@tie{}(@code{magit-snapshot-index})

Create a snapshot of the index only.  Unstaged and untracked changes
are not stashed.

@kindex z W
@cindex magit-snapshot-worktree
@item @kbd{z W} @tie{}@tie{}@tie{}@tie{}(@code{magit-snapshot-worktree})

Create a snapshot of unstaged changes in the working tree.
Untracked files are included according to infix arguments.  One
prefix argument is equivalent to @code{--include-untracked} while two
prefix arguments are equivalent to @code{--all}-.

@kindex z a
@cindex magit-stash-apply
@item @kbd{z a} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-apply})

Apply a stash to the working tree.  Try to preserve the stash index.
If that fails because there are staged changes, apply without
preserving the stash index.

@kindex z p
@cindex magit-stash-pop
@item @kbd{z p} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-pop})

Apply a stash to the working tree and remove it from stash list.
Try to preserve the stash index.  If that fails because there are
staged changes, apply without preserving the stash index and forgo
removing the stash.

@kindex z k
@cindex magit-stash-drop
@item @kbd{z k} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-drop})

Remove a stash from the stash list.  When the region is active, offer
to drop all contained stashes.

@kindex z v
@cindex magit-stash-show
@item @kbd{z v} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-show})

Show all diffs of a stash in a buffer.

@kindex z b
@cindex magit-stash-branch
@item @kbd{z b} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-branch})

Create and checkout a new BRANCH from STASH@.  The branch starts at
the commit that was current when the stash was created.

@kindex z B
@cindex magit-stash-branch-here
@item @kbd{z B} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-branch-here})

Create and checkout a new BRANCH using @code{magit-branch} with the current
branch or @code{HEAD} as the starting-point.  Then apply STASH, dropping it
if it applies cleanly.

@kindex z f
@cindex magit-stash-format-patch
@item @kbd{z f} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-format-patch})

Create a patch from STASH@.

@kindex k
@cindex magit-stash-clear
@item @kbd{k} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-clear})

Remove all stashes saved in REF's reflog by deleting REF@.

@kindex z l
@cindex magit-stash-list
@item @kbd{z l} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-list})

List all stashes in a buffer.

@end table

@defopt magit-stashes-margin

This option specifies whether the margin is initially shown in
stashes buffers and how it is formatted.

The value has the form @code{(INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH)}.

@itemize
@item
If INIT is non-nil, then the margin is shown initially.

@item
STYLE controls how to format the author or committer date.  It can
be one of @code{age} (to show the age of the commit), @code{age-abbreviated} (to
abbreviate the time unit to a character), or a string (suitable
for @code{format-time-string}) to show the actual date.  Option
@code{magit-log-margin-show-committer-date} controls which date is being
displayed.

@item
WIDTH controls the width of the margin.  This exists for forward
compatibility and currently the value should not be changed.

@item
AUTHOR controls whether the name of the author is also shown by
default.

@item
AUTHOR-WIDTH has to be an integer.  When the name of the author
is shown, then this specifies how much space is used to do so.
@end itemize
@end defopt

@node Transferring
@chapter Transferring

@menu
* Remotes::
* Fetching::
* Pulling::
* Pushing::
* Plain Patches::
* Maildir Patches::
@end menu

@node Remotes
@section Remotes

@menu
* Remote Commands::
* Remote Git Variables::
@end menu

@node Remote Commands
@subsection Remote Commands

The transient prefix command @code{magit-remote} is used to add remotes and
to make changes to existing remotes.  This command only deals with
remotes themselves, not with branches or the transfer of commits.
Those features are available from separate transient commands.

Also see 
@ifinfo
@ref{git-remote,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-remote">git-remote(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-remote(1) manpage.
@end iftex

@table @asis
@kindex M
@cindex magit-remote
@item @kbd{M} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote})

This transient prefix command binds the following suffix commands
and displays them in a temporary buffer until a suffix is invoked.

By default it also binds and displays the values of some
remote-related Git variables and allows changing their values.

@end table

@defopt magit-remote-direct-configure

This option controls whether remote-related Git variables are
accessible directly from the transient @code{magit-remote}.

If @code{t} (the default) and a local branch is checked out, then
@code{magit-remote} features the variables for the upstream remote of that
branch, or if @code{HEAD} is detached, for @code{origin}, provided that exists.

If @code{nil}, then @code{magit-remote-configure} has to be used to do so.
@end defopt

@table @asis
@kindex M C
@cindex magit-remote-configure
@item @kbd{M C} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote-configure})

This transient prefix command binds commands that set the value of
remote-related variables and displays them in a temporary buffer
until the transient is exited.

With a prefix argument, this command always prompts for a remote.

Without a prefix argument this depends on whether it was invoked as
a suffix of @code{magit-remote} and on the @code{magit-remote-direct-configure}
option.  If @code{magit-remote} already displays the variables for the
upstream, then it does not make sense to invoke another transient
that displays them for the same remote.  In that case this command
prompts for a remote.
@end table

The variables are described in @ref{Remote Git Variables}.

@table @asis
@kindex M a
@cindex magit-remote-add
@item @kbd{M a} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote-add})

This command add a remote and fetches it.  The remote name and url
are read in the minibuffer.

@kindex M r
@cindex magit-remote-rename
@item @kbd{M r} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote-rename})

This command renames a remote.  Both the old and the new names are
read in the minibuffer.

@kindex M u
@cindex magit-remote-set-url
@item @kbd{M u} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote-set-url})

This command changes the url of a remote.  Both the remote and the
new url are read in the minibuffer.

@kindex M k
@cindex magit-remote-remove
@item @kbd{M k} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote-remove})

This command deletes a remote, read in the minibuffer.

@kindex M p
@cindex magit-remote-prune
@item @kbd{M p} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote-prune})

This command removes stale remote-tracking branches for a remote
read in the minibuffer.

@kindex M P
@cindex magit-remote-prune-refspecs
@item @kbd{M P} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote-prune-refspecs})

This command removes stale refspecs for a remote read in the
minibuffer.

A refspec is stale if there no longer exists at least one branch
on the remote that would be fetched due to that refspec.  A stale
refspec is problematic because its existence causes Git to refuse
to fetch according to the remaining non-stale refspecs.

If only stale refspecs remain, then this command offers to either
delete the remote or to replace the stale refspecs with the default
refspec ("+refs/heads/*:refs/remotes/REMOTE/*").

This command also removes the remote-tracking branches that were
created due to the now stale refspecs.  Other stale branches are
not removed.

@end table

@defopt magit-remote-add-set-remote.pushDefault

This option controls whether the user is asked whether they want to
set @code{remote.pushDefault} after adding a remote.

If @code{ask}, then users is always ask.  If @code{ask-if-unset}, then the user is
only if the variable isn't set already.  If @code{nil}, then the user isn't
asked and the variable isn't set.  If the value is a string, then
the variable is set without the user being asked, provided that the
name of the added remote is equal to that string and the variable
isn't already set.
@end defopt

@node Remote Git Variables
@subsection Remote Git Variables

These variables can be set from the transient prefix command
@code{magit-remote-configure}.  By default they can also be set from
@code{magit-remote}.  See @ref{Remote Commands}.

@defvar remote.NAME.url

This variable specifies the url of the remote named NAME@.  It can
have multiple values.
@end defvar

@defvar remote.NAME.fetch

The refspec used when fetching from the remote named NAME@.  It can
have multiple values.
@end defvar

@defvar remote.NAME.pushurl

This variable specifies the url used for fetching from the remote
named NAME@.  If it is not specified, then @code{remote.NAME.url} is used
instead.  It can have multiple values.
@end defvar

@defvar remote.NAME.push

The refspec used when pushing to the remote named NAME@.  It can
have multiple values.
@end defvar

@defvar remote.NAME.tagOpts

This variable specifies what tags are fetched by default.  If the
value is @code{--no-tags} then no tags are fetched.  If the value is
@code{--tags}, then all tags are fetched.  If this variable has no value,
then only tags are fetched that are reachable from fetched branches.
@end defvar

@node Fetching
@section Fetching

Also see 
@ifinfo
@ref{git-fetch,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-fetch">git-fetch(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-fetch(1) manpage.
@end iftex
 For information about the upstream and the
push-remote, see @ref{The Two Remotes}.

@table @asis
@kindex f
@cindex magit-fetch
@item @kbd{f} @tie{}@tie{}@tie{}@tie{}(@code{magit-fetch})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.

@kindex f p
@cindex magit-fetch-from-pushremote
@item @kbd{f p} @tie{}@tie{}@tie{}@tie{}(@code{magit-fetch-from-pushremote})

This command fetches from the current push-remote.

With a prefix argument or when the push-remote is either not
configured or unusable, then let the user first configure the
push-remote.

@kindex f u
@cindex magit-fetch-from-upstream
@item @kbd{f u} @tie{}@tie{}@tie{}@tie{}(@code{magit-fetch-from-upstream})

This command fetch from the upstream of the current branch.

If the upstream is configured for the current branch and names
an existing remote, then use that.  Otherwise try to use another
remote: If only a single remote is configured, then use that.
Otherwise if a remote named "origin" exists, then use that.

If no remote can be determined, then this command is not available
from the @code{magit-fetch} transient prefix and invoking it directly
results in an error.

@kindex f e
@cindex magit-fetch-other
@item @kbd{f e} @tie{}@tie{}@tie{}@tie{}(@code{magit-fetch-other})

This command fetch from a repository read from the minibuffer.

@kindex f o
@cindex magit-fetch-branch
@item @kbd{f o} @tie{}@tie{}@tie{}@tie{}(@code{magit-fetch-branch})

This command fetches a branch from a remote, both of which are read
from the minibuffer.

@kindex f r
@cindex magit-fetch-refspec
@item @kbd{f r} @tie{}@tie{}@tie{}@tie{}(@code{magit-fetch-refspec})

This command fetches from a remote using an explicit refspec, both
of which are read from the minibuffer.

@kindex f a
@cindex magit-fetch-all
@item @kbd{f a} @tie{}@tie{}@tie{}@tie{}(@code{magit-fetch-all})

This command fetches from all remotes.

@kindex f m
@cindex magit-submodule-fetch
@item @kbd{f m} @tie{}@tie{}@tie{}@tie{}(@code{magit-submodule-fetch})

This command fetches all submodules.  With a prefix argument it
fetches all remotes of all submodules.

@end table

@defopt magit-pull-or-fetch

By default fetch and pull commands are available from separate
transient prefix command.  Setting this to @code{t} adds some (but not all)
of the above suffix commands to the @code{magit-pull} transient.

If you do that, then you might also want to change the key binding
for these prefix commands, e.g.:

@lisp
(setq magit-pull-or-fetch t)
(define-key magit-mode-map "f" 'magit-pull) ; was magit-fetch
(define-key magit-mode-map "F" nil)         ; was magit-pull
@end lisp
@end defopt

@node Pulling
@section Pulling

Also see 
@ifinfo
@ref{git-pull,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-pull">git-pull(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-pull(1) manpage.
@end iftex
 For information about the upstream and the
push-remote, see @ref{The Two Remotes}.

@table @asis
@kindex F
@cindex magit-pull
@item @kbd{F} @tie{}@tie{}@tie{}@tie{}(@code{magit-pull})

This transient prefix command binds the following suffix commands
and displays them in a temporary buffer until a suffix is invoked.

@kindex F p
@cindex magit-pull-from-pushremote
@item @kbd{F p} @tie{}@tie{}@tie{}@tie{}(@code{magit-pull-from-pushremote})

This command pulls from the push-remote of the current branch.

With a prefix argument or when the push-remote is either not
configured or unusable, then let the user first configure the
push-remote.

@kindex F u
@cindex magit-pull-from-upstream
@item @kbd{F u} @tie{}@tie{}@tie{}@tie{}(@code{magit-pull-from-upstream})

This command pulls from the upstream of the current branch.

With a prefix argument or when the upstream is either not
configured or unusable, then let the user first configure
the upstream.

@kindex F e
@cindex magit-pull-branch
@item @kbd{F e} @tie{}@tie{}@tie{}@tie{}(@code{magit-pull-branch})

This command pulls from a branch read in the minibuffer.
@end table

@node Pushing
@section Pushing

Also see 
@ifinfo
@ref{git-push,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-push">git-push(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-push(1) manpage.
@end iftex
 For information about the upstream and the
push-remote, see @ref{The Two Remotes}.

@table @asis
@kindex P
@cindex magit-push
@item @kbd{P} @tie{}@tie{}@tie{}@tie{}(@code{magit-push})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.

@kindex P p
@cindex magit-push-current-to-pushremote
@item @kbd{P p} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-current-to-pushremote})

This command pushes the current branch to its push-remote.

With a prefix argument or when the push-remote is either not
configured or unusable, then let the user first configure the
push-remote.

@kindex P u
@cindex magit-push-current-to-upstream
@item @kbd{P u} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-current-to-upstream})

This command pushes the current branch to its upstream branch.

With a prefix argument or when the upstream is either not
configured or unusable, then let the user first configure
the upstream.

@kindex P e
@cindex magit-push-current
@item @kbd{P e} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-current})

This command pushes the current branch to a branch read in the
minibuffer.

@kindex P o
@cindex magit-push-other
@item @kbd{P o} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-other})

This command pushes an arbitrary branch or commit somewhere.  Both
the source and the target are read in the minibuffer.

@kindex P r
@cindex magit-push-refspecs
@item @kbd{P r} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-refspecs})

This command pushes one or multiple refspecs to a remote, both of
which are read in the minibuffer.

To use multiple refspecs, separate them with commas.  Completion is
only available for the part before the colon, or when no colon is
used.

@kindex P m
@cindex magit-push-matching
@item @kbd{P m} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-matching})

This command pushes all matching branches to another repository.

If only one remote exists, then push to that.  Otherwise prompt for
a remote, offering the remote configured for the current branch as
default.

@kindex P t
@cindex magit-push-tags
@item @kbd{P t} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-tags})

This command pushes all tags to another repository.

If only one remote exists, then push to that.  Otherwise prompt for
a remote, offering the remote configured for the current branch as
default.

@kindex P T
@cindex magit-push-tag
@item @kbd{P T} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-tag})

This command pushes a tag to another repository.
@end table

Two more push commands exist, which by default are not available from
the push transient.  See their doc-strings for instructions on how to
add them to the transient.

@cindex magit-push-implicitly args
@deffn Command magit-push-implicitly args

This command pushes somewhere without using an explicit refspec.

This command simply runs @code{git push -v [ARGS]}.  ARGS are the infix
arguments.  No explicit refspec arguments are used.  Instead the
behavior depends on at least these Git variables: @code{push.default},
@code{remote.pushDefault}, @code{branch.<branch>.pushRemote},
@code{branch.<branch>.remote}, @code{branch.<branch>.merge}, and
@code{remote.<remote>.push}.
@end deffn

@cindex magit-push-to-remote remote args
@deffn Command magit-push-to-remote remote args

This command pushes to the remote REMOTE without using an explicit
refspec.  The remote is read in the minibuffer.

This command simply runs @code{git push -v [ARGS] REMOTE}.  ARGS are the
infix arguments.  No refspec arguments are used.  Instead the
behavior depends on at least these Git variables: @code{push.default},
@code{remote.pushDefault}, @code{branch.<branch>.pushRemote},
@code{branch.<branch>.remote}, @code{branch.<branch>.merge}, and
@code{remote.<remote>.push}.
@end deffn

@node Plain Patches
@section Plain Patches

@table @asis
@kindex W
@cindex magit-patch
@item @kbd{W} @tie{}@tie{}@tie{}@tie{}(@code{magit-patch})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.

@kindex W c
@cindex magit-patch-create
@item @kbd{W c} @tie{}@tie{}@tie{}@tie{}(@code{magit-patch-create})

This command creates patches for a set commits.  If the region marks
several commits, then it creates patches for all of them.  Otherwise
it functions as a transient prefix command, which features several
infix arguments and binds itself as a suffix command.  When this
command is invoked as a suffix of itself, then it creates a patch
using the specified infix arguments.

@kindex w a
@cindex magit-patch-apply
@item @kbd{w a} @tie{}@tie{}@tie{}@tie{}(@code{magit-patch-apply})

This command applies a patch.  This is a transient prefix command,
which features several infix arguments and binds itself as a suffix
command.  When this command is invoked as a suffix of itself, then
it applies a patch using the specified infix arguments.

@kindex W s
@cindex magit-patch-save
@item @kbd{W s} @tie{}@tie{}@tie{}@tie{}(@code{magit-patch-save})

This command creates a patch from the current diff.

Inside @code{magit-diff-mode} or @code{magit-revision-mode} buffers, @code{C-x C-w} is
also bound to this command.
@end table

It is also possible to save a plain patch file by using @code{C-x C-w} inside
a @code{magit-diff-mode} or @code{magit-revision-mode} buffer.

@node Maildir Patches
@section Maildir Patches

Also see 
@ifinfo
@ref{git-am,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-am">git-am(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-am(1) manpage.
@end iftex
 and 
@ifinfo
@ref{git-apply,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-apply">git-apply(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-apply(1) manpage.
@end iftex

@table @asis
@kindex w
@cindex magit-am
@item @kbd{w} @tie{}@tie{}@tie{}@tie{}(@code{magit-am})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.

@kindex w w
@cindex magit-am-apply-patches
@item @kbd{w w} @tie{}@tie{}@tie{}@tie{}(@code{magit-am-apply-patches})

This command applies one or more patches.  If the region marks
files, then those are applied as patches.  Otherwise this command
reads a file-name in the minibuffer, defaulting to the file at
point.

@kindex w m
@cindex magit-am-apply-maildir
@item @kbd{w m} @tie{}@tie{}@tie{}@tie{}(@code{magit-am-apply-maildir})

This command applies patches from a maildir.

@kindex w a
@cindex magit-patch-apply
@item @kbd{w a} @tie{}@tie{}@tie{}@tie{}(@code{magit-patch-apply})

This command applies a plain patch.  For a longer description see
@ref{Plain Patches}.  This command is only available from the @code{magit-am}
transient for historic reasons.
@end table

When an "am" operation is in progress, then the transient instead
features the following suffix commands.

@table @asis
@kindex w w
@cindex magit-am-continue
@item @kbd{w w} @tie{}@tie{}@tie{}@tie{}(@code{magit-am-continue})

This command resumes the current patch applying sequence.

@kindex w s
@cindex magit-am-skip
@item @kbd{w s} @tie{}@tie{}@tie{}@tie{}(@code{magit-am-skip})

This command skips the stopped at patch during a patch applying
sequence.

@kindex w a
@cindex magit-am-abort
@item @kbd{w a} @tie{}@tie{}@tie{}@tie{}(@code{magit-am-abort})

This command aborts the current patch applying sequence.  This
discards all changes made since the sequence started.
@end table

@node Miscellaneous
@chapter Miscellaneous

@menu
* Tagging::
* Notes::
* Submodules::
* Subtree::
* Worktree::
* Common Commands::
* Wip Modes::
* Minor Mode for Buffers Visiting Files::
* Minor Mode for Buffers Visiting Blobs::
@end menu

@node Tagging
@section Tagging

Also see 
@ifinfo
@ref{git-tag,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-tag">git-tag(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-tag(1) manpage.
@end iftex

@table @asis
@kindex t
@cindex magit-tag
@item @kbd{t} @tie{}@tie{}@tie{}@tie{}(@code{magit-tag})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.

@kindex t t
@cindex magit-tag-create
@item @kbd{t t} @tie{}@tie{}@tie{}@tie{}(@code{magit-tag-create})

This command creates a new tag with the given NAME at REV@.  With a
prefix argument it creates an annotate tag.

@kindex t r
@cindex magit-tag-release
@item @kbd{t r} @tie{}@tie{}@tie{}@tie{}(@code{magit-tag-release})

This commands creates an annotated release tag.  It assumes that
release tags match @code{magit-release-tag-regexp}.

First it prompts for the name of the new tag using the highest
existing tag as initial input and leaving it to the user to
increment the desired part of the version string.

Then it prompts for the message of the new tag.  The proposed tag
message is based on the message of the highest tag, provided that
that contains the corresponding version string and substituting the
new version string for that.  Otherwise it proposes something like
"Foo-Bar 1.2.3", given, for example, a TAG "v1.2.3" and a repository
located at something like "/path/to/foo-bar".

Then it calls "git tag --annotate --sign -m MSG TAG" to create the
tag, regardless of whether these arguments are enabled in the
transient.  Finally it shows the refs buffer to let the user quickly
review the result.

@kindex t k
@cindex magit-tag-delete
@item @kbd{t k} @tie{}@tie{}@tie{}@tie{}(@code{magit-tag-delete})

This command deletes one or more tags.  If the region marks multiple
tags (and nothing else), then it offers to delete those.  Otherwise,
it prompts for a single tag to be deleted, defaulting to the tag at
point.

@kindex t p
@cindex magit-tag-prune
@item @kbd{t p} @tie{}@tie{}@tie{}@tie{}(@code{magit-tag-prune})

This command offers to delete tags missing locally from REMOTE, and
vice versa.
@end table

@node Notes
@section Notes

Also see 
@ifinfo
@ref{git-notes,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-notes">git-notes(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-notes(1) manpage.
@end iftex

@table @asis
@kindex T
@cindex magit-notes
@item @kbd{T} @tie{}@tie{}@tie{}@tie{}(@code{magit-notes})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.

@kindex T T
@cindex magit-notes-edit
@item @kbd{T T} @tie{}@tie{}@tie{}@tie{}(@code{magit-notes-edit})

Edit the note attached to a commit, defaulting to the commit at
point.

By default use the value of Git variable @code{core.notesRef} or
"refs/notes/commits" if that is undefined.

@kindex T r
@cindex magit-notes-remove
@item @kbd{T r} @tie{}@tie{}@tie{}@tie{}(@code{magit-notes-remove})

Remove the note attached to a commit, defaulting to the commit at
point.

By default use the value of Git variable @code{core.notesRef} or
"refs/notes/commits" if that is undefined.

@kindex T p
@cindex magit-notes-prune
@item @kbd{T p} @tie{}@tie{}@tie{}@tie{}(@code{magit-notes-prune})

Remove notes about unreachable commits.
@end table

It is possible to merge one note ref into another.  That may result in
conflicts which have to resolved in the temporary worktree
".git/NOTES@math{_MERGE}@math{_WORKTREE}".

@table @asis
@kindex T m
@cindex magit-notes-merge
@item @kbd{T m} @tie{}@tie{}@tie{}@tie{}(@code{magit-notes-merge})

Merge the notes of a ref read from the user into the current notes
ref.  The current notes ref is the value of Git variable
@code{core.notesRef} or "refs/notes/commits" if that is undefined.
@end table

When a notes merge is in progress then the transient features the
following suffix commands, instead of those listed above.

@table @asis
@kindex T c
@cindex magit-notes-merge-commit
@item @kbd{T c} @tie{}@tie{}@tie{}@tie{}(@code{magit-notes-merge-commit})

Commit the current notes ref merge, after manually resolving
conflicts.

@kindex T a
@cindex magit-notes-merge-abort
@item @kbd{T a} @tie{}@tie{}@tie{}@tie{}(@code{magit-notes-merge-abort})

Abort the current notes ref merge.
@end table

The following variables control what notes reference @code{magit-notes-*},
@code{git notes} and @code{git show} act on and display.  Both the local and global
values are displayed and can be modified.

@defvar core.notesRef

This variable specifies the notes ref that is displayed by default
and which commands act on by default.
@end defvar

@defvar notes.displayRef

This variable specifies additional notes ref to be displayed in
addition to the ref specified by @code{core.notesRef}.  It can have
multiple values and may end with @code{*} to display all refs in the
@code{refs/notes/} namespace (or @code{**} if some names contain slashes).
@end defvar

@node Submodules
@section Submodules

Also see 
@ifinfo
@ref{git-submodule,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-submodule">git-submodule(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-submodule(1) manpage.
@end iftex

@menu
* Listing Submodules::
* Submodule Transient::
@end menu

@node Listing Submodules
@subsection Listing Submodules

The command @code{magit-list-submodules} displays a list of the current
repository's submodules in a separate buffer.  It's also possible to
display information about submodules directly in the status buffer of
the super-repository by adding @code{magit-insert-submodules} to the hook
@code{magit-status-sections-hook} as described in @ref{Status Module Sections}.

@cindex magit-list-submodules
@deffn Command magit-list-submodules

This command displays a list of the current repository's submodules
in a separate buffer.

It can be invoked by pressing @code{RET} on the section titled "Modules".
@end deffn

@defopt magit-submodule-list-columns

This option controls what columns are displayed by the command
@code{magit-list-submodules} and how they are displayed.

Each element has the form @code{(HEADER WIDTH FORMAT PROPS)}.

HEADER is the string displayed in the header.  WIDTH is the width of
the column.  FORMAT is a function that is called with one argument,
the repository identification (usually its basename), and with
@code{default-directory} bound to the toplevel of its working tree.  It
has to return a string to be inserted or nil.  PROPS is an alist
that supports the keys @code{:right-align} and @code{:pad-right}.
@end defopt

@defun magit-insert-submodules

Insert sections for all submodules.  For each section insert the
path, the branch, and the output of @code{git describe --tags},
or, failing that, the abbreviated HEAD commit hash.

Press @code{RET} on such a submodule section to show its own status buffer.
Press @code{RET} on the "Modules" section to display a list of submodules
in a separate buffer.  This shows additional information not
displayed in the super-repository's status buffer.
@end defun

@node Submodule Transient
@subsection Submodule Transient

@table @asis
@kindex o
@cindex magit-submodule
@item @kbd{o} @tie{}@tie{}@tie{}@tie{}(@code{magit-submodule})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.
@end table

Some of the below commands default to act on the modules that are
selected using the region.  For brevity their description talk about
"the selected modules", but if no modules are selected, then they act
on the current module instead, or if point isn't on a module, then the
read a single module to act on.  With a prefix argument these commands
ignore the selection and the current module and instead act on all
suitable modules.

@table @asis
@kindex o a
@cindex magit-submodule-add
@item @kbd{o a} @tie{}@tie{}@tie{}@tie{}(@code{magit-submodule-add})

This commands adds the repository at URL as a module.  Optional PATH
is the path to the module relative to the root of the super-project.
If it is nil then the path is determined based on URL@.

@kindex o r
@cindex magit-submodule-register
@item @kbd{o r} @tie{}@tie{}@tie{}@tie{}(@code{magit-submodule-register})

This command registers the selected modules by copying their urls
from ".gitmodules" to "$GIT@math{_DIR}/config".  These values can then be
edited before running @code{magit-submodule-populate}.  If you don't need
to edit any urls, then use the latter directly.

@kindex o p
@cindex magit-submodule-populate
@item @kbd{o p} @tie{}@tie{}@tie{}@tie{}(@code{magit-submodule-populate})

This command creates the working directory or directories of the
selected modules, checking out the recorded commits.

@kindex o u
@cindex magit-submodule-update
@item @kbd{o u} @tie{}@tie{}@tie{}@tie{}(@code{magit-submodule-update})

This command updates the selected modules checking out the recorded
commits.

@kindex o s
@cindex magit-submodule-synchronize
@item @kbd{o s} @tie{}@tie{}@tie{}@tie{}(@code{magit-submodule-synchronize})

This command synchronizes the urls of the selected modules, copying
the values from ".gitmodules" to the ".git/config" of the
super-project as well those of the modules.

@kindex o d
@cindex magit-submodule-unpopulate
@item @kbd{o d} @tie{}@tie{}@tie{}@tie{}(@code{magit-submodule-unpopulate})

This command removes the working directory of the selected modules.

@kindex o l
@cindex magit-list-submodules
@item @kbd{o l} @tie{}@tie{}@tie{}@tie{}(@code{magit-list-submodules})

This command displays a list of the current repository's modules.

@kindex o f
@cindex magit-fetch-modules
@item @kbd{o f} @tie{}@tie{}@tie{}@tie{}(@code{magit-fetch-modules})

This command fetches all modules.

Option @code{magit-fetch-modules-jobs} controls how many submodules are
being fetched in parallel.  Also fetch the super-repository, because
@code{git fetch} does not support not doing that.  With a prefix argument
fetch all remotes.
@end table

@node Subtree
@section Subtree

Also see 
@ifinfo
@ref{git-subtree,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-subtree">git-subtree(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-subtree(1) manpage.
@end iftex

@table @asis
@kindex O
@cindex magit-subtree
@item @kbd{O} @tie{}@tie{}@tie{}@tie{}(@code{magit-subtree})

This transient prefix command binds the two sub-transients; one for
importing a subtree and one for exporting a subtree.

@kindex O i
@cindex magit-subtree-import
@item @kbd{O i} @tie{}@tie{}@tie{}@tie{}(@code{magit-subtree-import})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.

The suffixes of this command import subtrees.

If the @code{--prefix} argument is set, then the suffix commands use that
prefix without prompting the user.  If it is unset, then they read
the prefix in the minibuffer.

@kindex O i a
@cindex magit-subtree-add
@item @kbd{O i a} @tie{}@tie{}@tie{}@tie{}(@code{magit-subtree-add})

This command adds COMMIT from REPOSITORY as a new subtree at PREFIX@.

@kindex O i c
@cindex magit-subtree-add-commit
@item @kbd{O i c} @tie{}@tie{}@tie{}@tie{}(@code{magit-subtree-add-commit})

This command add COMMIT as a new subtree at PREFIX@.

@kindex O i m
@cindex magit-subtree-merge
@item @kbd{O i m} @tie{}@tie{}@tie{}@tie{}(@code{magit-subtree-merge})

This command merges COMMIT into the PREFIX subtree.

@kindex O i f
@cindex magit-subtree-pull
@item @kbd{O i f} @tie{}@tie{}@tie{}@tie{}(@code{magit-subtree-pull})

This command pulls COMMIT from REPOSITORY into the PREFIX subtree.

@kindex O e
@cindex magit-subtree-export
@item @kbd{O e} @tie{}@tie{}@tie{}@tie{}(@code{magit-subtree-export})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.

The suffixes of this command export subtrees.

If the @code{--prefix} argument is set, then the suffix commands use that
prefix without prompting the user.  If it is unset, then they read
the prefix in the minibuffer.

@kindex O e p
@cindex magit-subtree-push
@item @kbd{O e p} @tie{}@tie{}@tie{}@tie{}(@code{magit-subtree-push})

This command extract the history of the subtree PREFIX and pushes it
to REF on REPOSITORY@.

@kindex O e s
@cindex magit-subtree-split
@item @kbd{O e s} @tie{}@tie{}@tie{}@tie{}(@code{magit-subtree-split})

This command extracts the history of the subtree PREFIX@.
@end table

@node Worktree
@section Worktree

Also see 
@ifinfo
@ref{git-worktree,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-worktree">git-worktree(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-worktree(1) manpage.
@end iftex

@table @asis
@kindex %
@cindex magit-worktree
@item @kbd{%} @tie{}@tie{}@tie{}@tie{}(@code{magit-worktree})

This transient prefix command binds the following suffix commands
and displays them in a temporary buffer until a suffix is invoked.

@kindex % b
@cindex magit-worktree-checkout
@item @kbd{% b} @tie{}@tie{}@tie{}@tie{}(@code{magit-worktree-checkout})

Checkout BRANCH in a new worktree at PATH@.

@kindex % c
@cindex magit-worktree-branch
@item @kbd{% c} @tie{}@tie{}@tie{}@tie{}(@code{magit-worktree-branch})

Create a new BRANCH and check it out in a new worktree at PATH@.

@kindex % m
@cindex magit-worktree-move
@item @kbd{% m} @tie{}@tie{}@tie{}@tie{}(@code{magit-worktree-move})

Move an existing worktree to a new PATH@.

@kindex % k
@cindex magit-worktree-delete
@item @kbd{% k} @tie{}@tie{}@tie{}@tie{}(@code{magit-worktree-delete})

Delete a worktree, defaulting to the worktree at point.
The primary worktree cannot be deleted.

@kindex % g
@cindex magit-worktree-status
@item @kbd{% g} @tie{}@tie{}@tie{}@tie{}(@code{magit-worktree-status})

Show the status for the worktree at point.

If there is no worktree at point, then read one in the minibuffer.
If the worktree at point is the one whose status is already being
displayed in the current buffer, then show it in Dired instead.
@end table

@node Common Commands
@section Common Commands

These are some of the commands that can be used in all buffers whose
major-modes derive from @code{magit-mode}.  There are other common commands
beside the ones below, but these didn't fit well anywhere else.

@table @asis
@kindex M-w
@cindex magit-copy-section-value
@item @kbd{M-w} @tie{}@tie{}@tie{}@tie{}(@code{magit-copy-section-value})

This command saves the value of the current section to the
@code{kill-ring}, and, provided that the current section is a commit,
branch, or tag section, it also pushes the (referenced) revision to
the @code{magit-revision-stack}.

When the current section is a branch or a tag, and a prefix argument
is used, then it saves the revision at its tip to the @code{kill-ring}
instead of the reference name.

When the region is active, this command saves that to the
@code{kill-ring}, like @code{kill-ring-save} would, instead of behaving as
described above.  If a prefix argument is used and the region is
within a hunk, it strips the outer diff marker column before saving
the text.

@kindex C-w
@cindex magit-copy-buffer-revision
@item @kbd{C-w} @tie{}@tie{}@tie{}@tie{}(@code{magit-copy-buffer-revision})

This command saves the revision being displayed in the current buffer
to the @code{kill-ring} and also pushes it to the @code{magit-revision-stack}.  It
is mainly intended for use in @code{magit-revision-mode} buffers, the only
buffers where it is always unambiguous exactly which revision should
be saved.

Most other Magit buffers usually show more than one revision, in
some way or another, so this command has to select one of them, and
that choice might not always be the one you think would have been
the best pick.
@end table

Outside of Magit @code{M-w} and @code{C-w} are usually bound to @code{kill-ring-save} and
@code{kill-region}, and these commands would also be useful in Magit buffers.
Therefore when the region is active, then both of these commands
behave like @code{kill-ring-save} instead of as described above.

@node Wip Modes
@section Wip Modes

Git keeps @strong{committed} changes around long enough for users to recover
changes they have accidentally deleted.  It does so by not garbage
collecting any committed but no longer referenced objects for a
certain period of time, by default 30 days.

But Git does @strong{not} keep track of @strong{uncommitted} changes in the working tree
and not even the index (the staging area).  Because Magit makes it so
convenient to modify uncommitted changes, it also makes it easy to
shoot yourself in the foot in the process.

For that reason Magit provides a global mode that saves @strong{tracked} files
to work-in-progress references after or before certain actions.  (At
present untracked files are never saved and for technical reasons
nothing is saved before the first commit has been created).

Two separate work-in-progress references are used to track the state
of the index and of the working tree: @code{refs/wip/index/<branchref>} and
@code{refs/wip/wtree/<branchref>}, where @code{<branchref>} is the full ref of the
current branch, e.g. @code{refs/heads/master}.  When the @code{HEAD} is detached
then @code{HEAD} is used in place of @code{<branchref>}.

Checking out another branch (or detaching @code{HEAD}) causes the use of
different wip refs for subsequent changes.

@defopt magit-wip-mode

When this mode is enabled, then uncommitted changes are committed
to dedicated work-in-progress refs whenever appropriate (i.e. when
dataloss would be a possibility otherwise).

Setting this variable directly does not take effect; either use the
Custom interface to do so or call the respective mode function.

For historic reasons this mode is implemented on top of four other
@code{magit-wip-*} modes, which can also be used individually, if you want
finer control over when the wip refs are updated; but that is
discouraged.  See @ref{Legacy Wip Modes}.
@end defopt

To view the log for a branch and its wip refs use the commands
@code{magit-wip-log} and @code{magit-wip-log-current}.  You should use @code{--graph} when
using these commands.

@cindex magit-wip-log
@deffn Command magit-wip-log

This command shows the log for a branch and its wip refs.
With a negative prefix argument only the worktree wip ref is shown.

The absolute numeric value of the prefix argument controls how many
"branches" of each wip ref are shown.  This is only relevant if the
value of @code{magit-wip-merge-branch} is @code{nil}.
@end deffn

@cindex magit-wip-log-current
@deffn Command magit-wip-log-current

This command shows the log for the current branch and its wip refs.
With a negative prefix argument only the worktree wip ref is shown.

The absolute numeric value of the prefix argument controls how many
"branches" of each wip ref are shown.  This is only relevant if the
value of @code{magit-wip-merge-branch} is @code{nil}.
@end deffn

@table @asis
@kindex X w
@cindex magit-reset-worktree
@item @kbd{X w} @tie{}@tie{}@tie{}@tie{}(@code{magit-reset-worktree})

This command resets the working tree to some commit read from the
user and defaulting to the commit at point, while keeping the @code{HEAD}
and index as-is.

This can be used to restore files to the state committed to a wip
ref.  Note that this will discard any unstaged changes that might
have existed before invoking this command (but of course only after
committing that to the working tree wip ref).
@end table

Note that even if you enable @code{magit-wip-mode} this won't give you
perfect protection.  The most likely scenario for losing changes
despite the use of @code{magit-wip-mode} is making a change outside Emacs and
then destroying it also outside Emacs.  In some such a scenario,
Magit, being an Emacs package, didn't get the opportunity to keep you
from shooting yourself in the foot.

When you are unsure whether Magit did commit a change to the wip refs,
then you can explicitly request that all changes to all tracked files
are being committed.

@table @asis
@kindex M-x magit-wip-commit
@cindex magit-wip-commit
@item @kbd{M-x magit-wip-commit} @tie{}@tie{}@tie{}@tie{}(@code{magit-wip-commit})

This command commits all changes to all tracked files to the index
and working tree work-in-progress refs.  Like the modes described above,
it does not commit untracked files, but it does check all tracked
files for changes.  Use this command when you suspect that the modes
might have overlooked a change made outside Emacs/Magit.

@end table

@defopt magit-wip-namespace

The namespace used for work-in-progress refs.  It has to end with
a slash.  The wip refs are named @code{<namespace>index/<branchref>} and
@code{<namespace>wtree/<branchref>}.  When snapshots are created while
the @code{HEAD} is detached then @code{HEAD} is used in place of @code{<branchref>}.
@end defopt

@defopt magit-wip-mode-lighter

Mode-line lighter for @code{magit-wip--mode}.
@end defopt

@menu
* Wip Graph::
* Legacy Wip Modes::
@end menu

@node Wip Graph
@subsection Wip Graph

@defopt magit-wip-merge-branch

This option controls whether the current branch is merged into the
wip refs after a new commit was created on the branch.

If non-nil and the current branch has new commits, then it is
merged into the wip ref before creating a new wip commit.  This
makes it easier to inspect wip history and the wip commits are
never garbage collected.

If nil and the current branch has new commits, then the wip ref
is reset to the tip of the branch before creating a new wip
commit.  With this setting wip commits are eventually garbage
collected.
@end defopt

When @code{magit-wip-merge-branch} is @code{t}, then the history looks like this:

@example
  *--*--*--*--*--*       refs/wip/index/refs/heads/master
 /     /     /
A-----B-----C            refs/heads/master
@end example

When @code{magit-wip-merge-branch} is @code{nil}, then creating a commit on the real
branch and then making a change causes the wip refs to be recreated to
fork from the new commit.  But the old commits on the wip refs are not
lost.  They are still available from the reflog.  To make it easier to
see when the fork point of a wip ref was changed, an additional commit
with the message "restart autosaving" is created on it (@code{xxO} commits
below are such boundary commits).

Starting with

@example
      BI0---BI1    refs/wip/index/refs/heads/master
     /
A---B              refs/heads/master
     \
      BW0---BW1    refs/wip/wtree/refs/heads/master
@end example

and committing the staged changes and editing and saving a file would
result in

@example
      BI0---BI1        refs/wip/index/refs/heads/master
     /
A---B---C              refs/heads/master
     \   \
      \   CW0---CW1    refs/wip/wtree/refs/heads/master
       \
        BW0---BW1      refs/wip/wtree/refs/heads/master@@@{2@}
@end example

The fork-point of the index wip ref is not changed until some change
is being staged.  Likewise just checking out a branch or creating a
commit does not change the fork-point of the working tree wip ref.  The
fork-points are not adjusted until there actually is a change that
should be committed to the respective wip ref.

@node Legacy Wip Modes
@subsection Legacy Wip Modes

It is recommended that you use the mode @code{magit-wip-mode} (which see) and
ignore the existence of the following modes, which are preserved for
historic reasons.

Setting the following variables directly does not take effect; either
use the Custom interface to do so or call the respective mode
functions.

@defopt magit-wip-after-save-mode

When this mode is enabled, then saving a buffer that visits a file
tracked in a Git repository causes its current state to be committed
to the working tree wip ref for the current branch.
@end defopt

@defopt magit-wip-after-apply-mode

When this mode is enabled, then applying (i.e. staging, unstaging,
discarding, reversing, and regularly applying) a change to a file
tracked in a Git repository causes its current state to be committed
to the index and/or working tree wip refs for the current branch.
@end defopt

If you only ever edit files using Emacs and only ever interact with
Git using Magit, then the above two modes should be enough to protect
each and every change from accidental loss.  In practice nobody does
that.  Two additional modes exists that do commit to the wip refs
before making changes that could cause the loss of earlier changes.

@defopt magit-wip-before-change-mode

When this mode is enabled, then certain commands commit the existing
changes to the files they are about to make changes to.
@end defopt

@defopt magit-wip-initial-backup-mode

When this mode is enabled, then the current version of a file is
committed to the worktree wip ref before the buffer visiting that
file is saved for the first time since the buffer was created.

This backs up the same version of the file that @code{backup-buffer} would
save.  While @code{backup-buffer} uses a backup file, this mode uses the
same worktree wip ref as used by the other Magit Wip modes.  Like
@code{backup-buffer}, it only does this once; unless you kill the buffer
and visit the file again only one backup will be created per Emacs
session.

This mode ignores the variables that affect @code{backup-buffer} and can be
used along-side that function, which is recommended because it only
backs up files that are tracked in a Git repository.
@end defopt

@defopt magit-wip-after-save-local-mode-lighter

Mode-line lighter for @code{magit-wip-after-save-local-mode}.
@end defopt

@defopt magit-wip-after-apply-mode-lighter

Mode-line lighter for @code{magit-wip-after-apply-mode}.
@end defopt

@defopt magit-wip-before-change-mode-lighter

Mode-line lighter for @code{magit-wip-before-change-mode}.
@end defopt

@defopt magit-wip-initial-backup-mode-lighter

Mode-line lighter for @code{magit-wip-initial-backup-mode}.
@end defopt

@node Minor Mode for Buffers Visiting Files
@section Minor Mode for Buffers Visiting Files

The minor-mode @code{magit-file-mode} enables certain Magit features in
file-visiting buffers belonging to a Git repository.  The globalized
variant @code{global-magit-file-mode} enables the local mode in all such
buffers.  It is enabled by default.  Currently the local mode only
establishes a few key bindings, but this might be extended in the
future.

@defopt global-magit-file-mode

Whether to establish certain Magit key bindings in all file-visiting
buffers belonging to any Git repository.  This is enabled by default.
This globalized mode turns on the local minor-mode @code{magit-file-mode}
in all suitable buffers.
@end defopt

@defvar magit-file-mode-map

This keymap is used by the local minor-mode @code{magit-file-mode} and
establishes the key bindings described below.

Note that the default binding for @code{magit-file-dispatch} is very
cumbersome to use and that we recommend that you add a better
binding.

Instead of @code{C-c M-g} I would have preferred to use @code{C-c g} because (1)
it is similar to @code{C-x g} (the recommended global binding for
@code{~magit-status}), (2) we cannot use @code{C-c C-g} because we have been
recommending that that be bound to @code{magit-dispatch} for a long time,
(3) we cannot use @code{C-x C-g} because that is a convenient way of
aborting the incomplete key sequence @code{C-x}, and most importantly (4)
it would make it much easier to type the next key (a suffix binding)
because most of those are letters.

For example @code{C-c g b} is much easier to type than @code{C-c M-g b}.  For
suffix bindings that use uppercase letters, the default is just
horrible—having to use e.g. @code{C-c M-g B} (@code{Control+c Meta+g Shift+b})
would drive anyone up the walls (or to Vim).

However @code{C-c LETTER} bindings are reserved for users (see
@ref{Key Binding Conventions,,,elisp,}).  Packages are forbidden from
using those.  Doing so anyway is considered heresy.  Therefore if
you want a better binding, you have to add it yourself:

@lisp
(define-key magit-file-mode-map
  (kbd "C-c g") 'magit-file-dispatch)
@end lisp
@end defvar

The key bindings shown below assume that you have not improved the
binding for @code{magit-file-dispatch}.

@table @asis
@kindex C-c M-g
@cindex magit-file-dispatch
@item @kbd{C-c M-g} @tie{}@tie{}@tie{}@tie{}(@code{magit-file-dispatch})

This transient prefix command binds the following suffix commands
and displays them in a temporary buffer until a suffix is invoked.

@kindex C-c M-g s
@cindex magit-stage-file
@item @kbd{C-c M-g s} @tie{}@tie{}@tie{}@tie{}(@code{magit-stage-file})

Stage all changes to the file being visited in the current buffer.

@kindex C-c M-g u
@cindex magit-unstage-file
@item @kbd{C-c M-g u} @tie{}@tie{}@tie{}@tie{}(@code{magit-unstage-file})

Unstage all changes to the file being visited in the current buffer.

@kindex C-c M-g c
@cindex magit-commit
@item @kbd{C-c M-g c} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit})

This transient prefix command binds the following suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.  See @ref{Initiating a Commit}.

@kindex C-c M-g D
@cindex magit-diff
@item @kbd{C-c M-g D} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff})

This transient prefix command binds several diff suffix commands and
infix arguments and displays them in a temporary buffer until a
suffix is invoked.  See @ref{Diffing}.

This is the same command that @code{d} is bound to in Magit buffers.
If this command is invoked from a file-visiting buffer, then the
initial value of the option (@code{--}) that limits the diff to certain
file(s) is set to the visited file.

@kindex C-c M-g d
@cindex magit-diff-buffer-file
@item @kbd{C-c M-g d} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-buffer-file})

This command shows the diff for the file of blob that the current
buffer visits.

@end table

@defopt magit-diff-buffer-file-locked

This option controls whether @code{magit-diff-buffer-file} uses a dedicated
buffer.  See @ref{Modes and Buffers}.
@end defopt

@table @asis
@kindex C-c M-g L
@cindex magit-log
@item @kbd{C-c M-g L} @tie{}@tie{}@tie{}@tie{}(@code{magit-log})

This transient prefix command binds several log suffix commands and
infix arguments and displays them in a temporary buffer until a
suffix is invoked.  See @ref{Logging}.

This is the same command that @code{l} is bound to in Magit buffers.
If this command is invoked from a file-visiting buffer, then the
initial value of the option (@code{--}) that limits the log to certain
file(s) is set to the visited file.

@kindex C-c M-g l
@cindex magit-log-buffer-file
@item @kbd{C-c M-g l} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-buffer-file})

This command shows the log for the file of blob that the current
buffer visits.  Renames are followed when a prefix argument is used
or when @code{--follow} is an active log argument.  When the region is
active, the log is restricted to the selected line range.

@kindex C-c M-g t
@cindex magit-log-trace-definition
@item @kbd{C-c M-g t} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-trace-definition})

This command shows the log for the definition at point.

@end table

@defopt magit-log-buffer-file-locked

This option controls whether @code{magit-log-buffer-file} uses a dedicated
buffer.  See @ref{Modes and Buffers}.
@end defopt

@table @asis
@kindex C-c M-g B
@cindex magit-blame
@item @kbd{C-c M-g B} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame})

This transient prefix command binds all blaming suffix commands
along with the appropriate infix arguments and displays them in a
temporary buffer until a suffix is invoked.

For more information about this and the following commands also see
@ref{Blaming}.
@end table

In addition to the @code{magit-blame} sub-transient, the dispatch transient
also binds several blaming suffix commands directly.  See @ref{Blaming} for
information about those commands and bindings.

@table @asis
@kindex C-c M-g e
@cindex magit-edit-line-commit
@item @kbd{C-c M-g e} @tie{}@tie{}@tie{}@tie{}(@code{magit-edit-line-commit})

This command makes the commit editable that added the current line.

With a prefix argument it makes the commit editable that removes the
line, if any.  The commit is determined using @code{git blame} and made
editable using @code{git rebase --interactive} if it is reachable from
@code{HEAD}, or by checking out the commit (or a branch that points at it)
otherwise.

@kindex C-c M-g p
@cindex magit-blob-previous
@item @kbd{C-c M-g p} @tie{}@tie{}@tie{}@tie{}(@code{magit-blob-previous})

Visit the previous blob which modified the current file.
@end table

There are a few additional commands that operate on a single file but
are not enabled in the file transient command by default:

@cindex magit-file-rename
@deffn Command magit-file-rename

This command renames a file read from the user.
@end deffn

@cindex magit-file-delete
@deffn Command magit-file-delete

This command deletes a file read from the user.
@end deffn

@cindex magit-file-untrack
@deffn Command magit-file-untrack

This command untracks a file read from the user.
@end deffn

@cindex magit-file-checkout
@deffn Command magit-file-checkout

This command updates a file in the working tree and index to the
contents from a revision.  Both the revision and file are read
from the user.
@end deffn

To enable them invoke the transient (@code{C-c M-g}), enter "edit mode" (@code{C-x
l}), set the "transient level" (@code{C-x l} again), enter @code{5}, and leave edit
mode (@code{C-g}).  Also see @ref{Enabling and Disabling Suffixes,,,transient,}.

@node Minor Mode for Buffers Visiting Blobs
@section Minor Mode for Buffers Visiting Blobs

The @code{magit-blob-mode} enables certain Magit features in blob-visiting
buffers.  Such buffers can be created using @code{magit-find-file} and some
of the commands mentioned below, which also take care of turning on
this minor mode.  Currently this mode only establishes a few key
bindings, but this might be extended.

@table @asis
@kindex p
@cindex magit-blob-previous
@item @kbd{p} @tie{}@tie{}@tie{}@tie{}(@code{magit-blob-previous})

Visit the previous blob which modified the current file.

@kindex n
@cindex magit-blob-next
@item @kbd{n} @tie{}@tie{}@tie{}@tie{}(@code{magit-blob-next})

Visit the next blob which modified the current file.

@kindex q
@cindex magit-kill-this-buffer
@item @kbd{q} @tie{}@tie{}@tie{}@tie{}(@code{magit-kill-this-buffer})

Kill the current buffer.
@end table

@node Customizing
@chapter Customizing

Both Git and Emacs are highly customizable.  Magit is both a Git
porcelain as well as an Emacs package, so it makes sense to customize
it using both Git variables as well as Emacs options.  However this
flexibility doesn't come without problems, including but not limited
to the following.

@itemize
@item
Some Git variables automatically have an effect in Magit without
requiring any explicit support.  Sometimes that is desirable - in
other cases, it breaks Magit.

When a certain Git setting breaks Magit but you want to keep using
that setting on the command line, then that can be accomplished by
overriding the value for Magit only by appending something like
@code{("-c" "some.variable=compatible-value")} to
@code{magit-git-global-arguments}.


@item
Certain settings like @code{fetch.prune=true} are respected by Magit
commands (because they simply call the respective Git command) but
their value is not reflected in the respective transient buffers.
In this case the @code{--prune} argument in @code{magit-fetch} might be active or
inactive, but that doesn't keep the Git variable from being honored
by the suffix commands anyway.  So pruning might happen despite the
@code{--prune} arguments being displayed in a way that seems to indicate
that no pruning will happen.
@end itemize

I intend to address these and similar issues in a future release.

@menu
* Per-Repository Configuration::
* Essential Settings::
@end menu

@node Per-Repository Configuration
@section Per-Repository Configuration

Magit can be configured on a per-repository level using both Git
variables as well as Emacs options.

To set a Git variable for one repository only, simply set it in
@code{/path/to/repo/.git/config} instead of @code{$HOME/.gitconfig} or
@code{/etc/gitconfig}.  See 
@ifinfo
@ref{git-config,,,gitman,}.
@end ifinfo
@ifhtml
@html
the <a href="http://git-scm.com/docs/git-config">git-config(1)</a> manpage.
@end html
@end ifhtml
@iftex
the git-config(1) manpage.
@end iftex

Similarly, Emacs options can be set for one repository only by editing
@code{/path/to/repo/.dir-locals.el}.  See @ref{Directory Variables,,,emacs,}.
For example to disable automatic refreshes of file-visiting buffers in
just one huge repository use this:

@itemize
@item
@code{/path/to/huge/repo/.dir-locals.el}

@lisp
((nil . ((magit-refresh-buffers . nil))))
@end lisp
@end itemize

It might only be costly to insert certain information into Magit
buffers for repositories that are exceptionally large, in which case
you can disable the respective section inserters just for that
repository:

@itemize
@item
@code{/path/to/tag/invested/repo/.dir-locals.el}

@lisp
((magit-status-mode
  . ((eval . (magit-disable-section-inserter 'magit-insert-tags-header)))))
@end lisp

@end itemize

@defun magit-disable-section-inserter fn

This function disables the section inserter FN in the current
repository.  It is only intended for use in @code{.dir-locals.el} and
@code{.dir-locals-2.el}.
@end defun

If you want to apply the same settings to several, but not all,
repositories then keeping the repository-local config files in sync
would quickly become annoying.  To avoid that you can create config
files for certain classes of repositories (e.g. "huge repositories")
and then include those files in the per-repository config files.
For example:

@itemize
@item
@code{/path/to/huge/repo/.git/config}

@example
[include]
        path = /path/to/huge-gitconfig
@end example


@item
@code{/path/to/huge-gitconfig}

@example
[status]
        showUntrackedFiles = no
@end example


@item
@code{$HOME/.emacs.d/init.el}

@lisp
(dir-locals-set-class-variables 'huge-git-repository
   '((nil . ((magit-refresh-buffers . nil)))))

(dir-locals-set-directory-class
   "/path/to/huge/repo/" 'huge-git-repository)
@end lisp
@end itemize

@node Essential Settings
@section Essential Settings

The next two sections list and discuss several variables that many
users might want to customize, for safety and/or performance reasons.

@menu
* Safety::
* Performance::
@end menu

@node Safety
@subsection Safety

This section discusses various variables that you might want to
change (or @strong{not} change) for safety reasons.

Git keeps @strong{committed} changes around long enough for users to recover
changes they have accidentally been deleted.  It does not do the same
for @strong{uncommitted} changes in the working tree and not even the index
(the staging area).  Because Magit makes it so easy to modify
uncommitted changes, it also makes it easy to shoot yourself in the
foot in the process.  For that reason Magit provides three global
modes that save @strong{tracked} files to work-in-progress references after or
before certain actions.  See @ref{Wip Modes}.

These modes are not enabled by default because of performance
concerns.  Instead a lot of potentially destructive commands require
confirmation every time they are used.  In many cases this can be
disabled by adding a symbol to @code{magit-no-confirm} (see @ref{Completion and Confirmation}).  If you enable the various wip modes then you should
add @code{safe-with-wip} to this list.

Similarly it isn't necessary to require confirmation before moving a
file to the system trash - if you trashed a file by mistake then you
can recover it from there.  Option @code{magit-delete-by-moving-to-trash}
controls whether the system trash is used, which is the case by default.
Nevertheless, @code{trash} isn't a member of @code{magit-no-confirm} - you
might want to change that.

By default buffers visiting files are automatically reverted when the
visited file changes on disk.  This isn't as risky as it might seem,
but to make an informed decision you should see @ref{Risk of Reverting Automatically}.

@node Performance
@subsection Performance

After Magit has run @code{git} for side-effects, it also refreshes the
current Magit buffer and the respective status buffer.  This is
necessary because otherwise outdated information might be displayed
without the user noticing.  Magit buffers are updated by recreating
their content from scratch, which makes updating simpler and less
error-prone, but also more costly.  Keeping it simple and just
re-creating everything from scratch is an old design decision and
departing from that will require major refactoring.

I plan to do that in time for the next major release.  I also intend
to create logs and diffs asynchronously, which should also help a lot
but also requires major refactoring.

Meanwhile you can tell Magit to only automatically refresh the current
Magit buffer, but not the status buffer.  If you do that, then the
status buffer is only refreshed automatically if it is the
current buffer.

@lisp
(setq magit-refresh-status-buffer nil)
@end lisp

You should also check whether any third-party packages have added
anything to @code{magit-refresh-buffer-hook}, @code{magit-status-refresh-hook},
@code{magit-pre-refresh-hook}, and @code{magit-post-refresh-hook}.  If so, then
check whether those additions impact performance significantly.

Magit can be told to refresh buffers verbosely using @code{M-x
magit-toggle-verbose-refresh}.  Enabling this helps figuring out which
sections are bottlenecks.  The additional output can be found in the
@code{*Messages*} buffer.

Magit also reverts buffers for visited files located inside the
current repository when the visited file changes on disk.  That is
implemented on top of @code{auto-revert-mode} from the built-in library
@code{autorevert}.  To figure out whether that impacts performance, check
whether performance is significantly worse, when many buffers exist
and/or when some buffers visit files using TRAMP@.  If so, then this
should help.

@lisp
(setq auto-revert-buffer-list-filter
      'magit-auto-revert-repository-buffer-p)
@end lisp

For alternative approaches see @ref{Automatic Reverting of File-Visiting Buffers}.

If you have enabled any features that are disabled by default, then
you should check whether they impact performance significantly.  It's
likely that they were not enabled by default because it is known that
they reduce performance at least in large repositories.

If performance is only slow inside certain unusually large
repositories, then you might want to disable certain features on a
per-repository or per-repository-class basis only.  See
@ref{Per-Repository Configuration}.  For example it takes a long time to
determine the next and current tag in repository with exceptional
numbers of tags.  It would therefore be a good idea to disable
@code{magit-insert-tags-headers}, as explained at the mentioned node.

@menu
* Microsoft Windows Performance::
* MacOS Performance::
@end menu

@unnumberedsubsubsec Log Performance

When showing logs, Magit limits the number of commits initially shown
in the hope that this avoids unnecessary work.  When using @code{--graph} is
used, then this unfortunately does not have the desired effect for
large histories.  Junio, Git's maintainer, said on the git mailing
list (@uref{http://www.spinics.net/lists/git/msg232230.html}): "@code{--graph} wants
to compute the whole history and the max-count only affects the output
phase after @code{--graph} does its computation".

In other words, it's not that Git is slow at outputting the
differences, or that Magit is slow at parsing the output - the problem
is that Git first goes outside and has a smoke.

We actually work around this issue by limiting the number of commits
not only by using @code{-<N>} but by also using a range.  But unfortunately
that's not always possible.

When more than a few thousand commits are shown, then the use of
@code{--graph} can slow things down.

Using @code{--color --graph} is even slower.  Magit uses code that is part of
Emacs to turn control characters into faces.  That code is pretty slow
and this is quite noticeable when showing a log with many branches and
merges.  For that reason @code{--color} is not enabled by default anymore.
Consider leaving it at that.

@unnumberedsubsubsec Diff Performance

If diffs are slow, then consider turning off some optional diff
features by setting all or some of the following variables to @code{nil}:
@code{magit-diff-highlight-indentation}, @code{magit-diff-highlight-trailing},
@code{magit-diff-paint-whitespace}, @code{magit-diff-highlight-hunk-body}, and
@code{magit-diff-refine-hunk}.

When showing a commit instead of some arbitrary diff, then some
additional information is displayed.  Calculating this information
can be quite expensive given certain circumstances.  If looking at
a commit using @code{magit-revision-mode} takes considerably more time than
looking at the same commit in @code{magit-diff-mode}, then consider setting
@code{magit-revision-insert-related-refs} to @code{nil}.

When you are often confronted with diffs that contain deleted files,
then you might want to enable the @code{--irreversible-delete} argument.  If
you do that then diffs still show that a file was deleted but without
also showing the complete deleted content of the file.  This argument
is not available by default, see @ref{Enabling and Disabling Suffixes,,,transient,}.  Once you have done that you should enable it and save that
setting, see @ref{Saving Values,,,transient,}.  You should do this in both
the diff (@code{d}) and the diff refresh (@code{D}) transient popups.

@unnumberedsubsubsec Refs Buffer Performance

When refreshing the "references buffer" is slow, then that's usually
because several hundred refs are being displayed.  The best way to
address that is to display fewer refs, obviously.

If you are not, or only mildly, interested in seeing the list of tags,
then start by not displaying them:

@lisp
(remove-hook 'magit-refs-sections-hook 'magit-insert-tags)
@end lisp

Then you should also make sure that the listed remote branches
actually all exist.  You can do so by pruning branches which no longer
exist using @code{f-pa}.

@unnumberedsubsubsec Committing Performance

When you initiate a commit, then Magit by default automatically shows
a diff of the changes you are about to commit.  For large commits this
can take a long time, which is especially distracting when you are
committing large amounts of generated data which you don't actually
intend to inspect before committing.  This behavior can be turned off
using:

@lisp
(remove-hook 'server-switch-hook 'magit-commit-diff)
@end lisp

Then you can type @code{C-c C-d} to show the diff when you actually want to
see it, but only then.  Alternatively you can leave the hook alone and
just type @code{C-g} in those cases when it takes too long to generate the
diff.  If you do that, then you will end up with a broken diff buffer,
but doing it this way has the advantage that you usually get to see
the diff, which is useful because it increases the odds that you spot
potential issues.

@unnumberedsubsubsec The Built-In VC Package

Emacs comes with a version control interface called "VC", see
@ref{Version Control,,,emacs,}.  It is enabled be default, and if you don't
use it in addition to Magit, then you should disable it to keep it
from performing unnecessary work:

@lisp
(setq vc-handled-backends nil)
@end lisp

You can also disable its use for Git but keep using it when using
another version control system:

@lisp
(setq vc-handled-backends (delq 'Git vc-handled-backends))
@end lisp

@node Microsoft Windows Performance
@unnumberedsubsubsec Microsoft Windows Performance

In order to update the status buffer, @code{git} has to be run a few dozen
times.  That is problematic on Microsoft Windows, because that
operating system is exceptionally slow at starting processes.  Sadly
this is an issue that can only be fixed by Microsoft itself, and they
don't appear to be particularly interested in doing so.

Beside the subprocess issue, there are also other Windows-specific
performance issues. Some of these have workarounds.  The
maintainers of "Git for Windows" try to improve performance on Windows.
Always use the latest release in order to benefit from the latest
performance tweaks.  Magit too tries to work around some
Windows-specific issues.

According to some sources, setting the following Git variables can also
help.

@example
git config --global core.preloadindex true   # default since v2.1
git config --global core.fscache true        # default since v2.8
git config --global gc.auto 256
@end example

You should also check whether an anti-virus program is affecting
performance.

@node MacOS Performance
@unnumberedsubsubsec MacOS Performance

Before Emacs 26.1 child processes were created using @code{fork} on macOS@.
That needlessly copied GUI resources, which is expensive.  The result
was that forking took about 30 times as long on Darwin than on Linux,
and because Magit starts many @code{git} processes that made quite a
difference.

So make sure that you are using at least Emacs 26.1, in which case the
faster @code{vfork} will be used.  (The creation of child processes still
takes about twice as long on Darwin compared to Linux.)  See @footnote{@uref{https://lists.gnu.org/archive/html/bug-gnu-emacs/2017-04/msg00201.html}}
for more information.

On Catalina, and potentially other macOS releases, there may be a
performance problem where any action takes 20 times longer on Darwin
than on Linux.  This can be fixed by setting @code{magit-git-executable} to
the absolute path of the @code{git} executable, instead of relying on
resolving the @code{$PATH}.

@node Plumbing
@chapter Plumbing

The following sections describe how to use several of Magit's core
abstractions to extend Magit itself or implement a separate extension.

A few of the low-level features used by Magit have been factored out
into separate libraries/packages, so that they can be used by other
packages, without having to depend on Magit.  See @ref{Top,,,with-editor,} for
information about @code{with-editor}.  @code{transient} doesn't have a manual yet.

If you are trying to find an unused key that you can bind to a
command provided by your own Magit extension, then checkout
@uref{https://github.com/magit/magit/wiki/Plugin-Dispatch-Key-Registry}.

@menu
* Calling Git::
* Section Plumbing::
* Refreshing Buffers::
* Conventions::
@end menu

@node Calling Git
@section Calling Git

Magit provides many specialized functions for calling Git.  All of
these functions are defined in either @code{magit-git.el} or @code{magit-process.el}
and have one of the prefixes @code{magit-run-}, @code{magit-call-}, @code{magit-start-},
or @code{magit-git-} (which is also used for other things).

All of these functions accept an indefinite number of arguments, which
are strings that specify command line arguments for Git (or in some
cases an arbitrary executable).  These arguments are flattened before
being passed on to the executable; so instead of strings they can also
be lists of strings and arguments that are @code{nil} are silently dropped.
Some of these functions also require a single mandatory argument
before these command line arguments.

Roughly speaking, these functions run Git either to get some value or
for side-effects.  The functions that return a value are useful to
collect the information necessary to populate a Magit buffer, while
the others are used to implement Magit commands.

The functions in the value-only group always run synchronously, and
they never trigger a refresh.  The function in the side-effect group
can be further divided into subgroups depending on whether they run
Git synchronously or asynchronously, and depending on whether they
trigger a refresh when the executable has finished.

@menu
* Getting a Value from Git::
* Calling Git for Effect::
@end menu

@node Getting a Value from Git
@subsection Getting a Value from Git

These functions run Git in order to get a value, an exit
status, or output.  Of course you could also use them to run Git
commands that have side-effects, but that should be avoided.

@defun magit-git-exit-code &rest args

Executes git with ARGS and returns its exit code.
@end defun

@defun magit-git-success &rest args

Executes git with ARGS and returns @code{t} if the exit code is @code{0}, @code{nil}
otherwise.
@end defun

@defun magit-git-failure &rest args

Executes git with ARGS and returns @code{t} if the exit code is @code{1}, @code{nil}
otherwise.
@end defun

@defun magit-git-true &rest args

Executes git with ARGS and returns @code{t} if the first line printed by
git is the string "true", @code{nil} otherwise.
@end defun

@defun magit-git-false &rest args

Executes git with ARGS and returns @code{t} if the first line printed by
git is the string "false", @code{nil} otherwise.
@end defun

@defun magit-git-insert &rest args

Executes git with ARGS and inserts its output at point.
@end defun

@defun magit-git-string &rest args

Executes git with ARGS and returns the first line of its output.  If
there is no output or if it begins with a newline character, then
this returns @code{nil}.
@end defun

@defun magit-git-lines &rest args

Executes git with ARGS and returns its output as a list of lines.
Empty lines anywhere in the output are omitted.
@end defun

@defun magit-git-items &rest args

Executes git with ARGS and returns its null-separated output as a
list.  Empty items anywhere in the output are omitted.

If the value of option @code{magit-git-debug} is non-nil and git exits with
a non-zero exit status, then warn about that in the echo area and
add a section containing git's standard error in the current
repository's process buffer.
@end defun

If an error occurs when using one of the above functions, then that
is usually due to a bug, i.e. using an argument which is not
actually supported.  Such errors are usually not reported, but when
they occur we need to be able to debug them.

@defopt magit-git-debug

Whether to report errors that occur when using @code{magit-git-insert},
@code{magit-git-string}, @code{magit-git-lines}, or @code{magit-git-items}.  This does
not actually raise an error.  Instead a message is shown in the echo
area, and git's standard error is insert into a new section in the
current repository's process buffer.
@end defopt

@defun magit-git-str &rest args

This is a variant of @code{magit-git-string} that ignores the option
@code{magit-git-debug}.  It is mainly intended to be used while handling
errors in functions that do respect that option.  Using such a
function while handing an error could cause yet another error and
therefore lead to an infinite recursion.  You probably won't ever
need to use this function.
@end defun

@node Calling Git for Effect
@subsection Calling Git for Effect

These functions are used to run git to produce some effect.  Most
Magit commands that actually run git do so by using such a function.

Because we do not need to consume git's output when using these
functions, their output is instead logged into a per-repository
buffer, which can be shown using @code{$} from a Magit buffer or @code{M-x
magit-process} elsewhere.

These functions can have an effect in two distinct ways.  Firstly,
running git may change something, i.e. create or push a new commit.
Secondly, that change may require that Magit buffers are refreshed to
reflect the changed state of the repository.  But refreshing isn't
always desirable, so only some of these functions do perform such a
refresh after git has returned.

Sometimes it is useful to run git asynchronously.  For example, when
the user has just initiated a push, then there is no reason to make
her wait until that has completed.  In other cases it makes sense to
wait for git to complete before letting the user do something else.
For example after staging a change it is useful to wait until after
the refresh because that also automatically moves to the next change.

@defun magit-call-git &rest args

Calls git synchronously with ARGS@.
@end defun

@defun magit-call-process program &rest args

Calls PROGRAM synchronously with ARGS@.
@end defun

@defun magit-run-git &rest args

Calls git synchronously with ARGS and then refreshes.
@end defun

@defun magit-run-git-with-input input &rest args

Calls git synchronously with ARGS and sends it INPUT on standard
input.

INPUT should be a buffer or the name of an existing buffer.  The
content of that buffer is used as the process' standard input.
After the process returns a refresh is performed.

As a special case, INPUT may also be nil.  In that case the content
of the current buffer is used as standard input and @strong{no} refresh is
performed.

This function actually runs git asynchronously.  But then it waits
for the process to return, so the function itself is synchronous.
@end defun

@defun magit-run-git-with-logfile file &rest args

Calls git synchronously with ARGS@.  The process' output is saved in
FILE@.  This is rarely useful and so this function might be removed
in the future.

This function actually runs git asynchronously.  But then it waits
for the process to return, so the function itself is synchronous.
@end defun

@defun magit-git &rest args

Calls git synchronously with ARGS for side-effects only.  This
function does not refresh the buffer.
@end defun

@defun magit-git-wash washer &rest args

Execute Git with ARGS, inserting washed output at point.  Actually
first insert the raw output at point.  If there is no output call
@code{magit-cancel-section}.  Otherwise temporarily narrow the buffer to
the inserted text, move to its beginning, and then call function
WASHER with ARGS as its sole argument.
@end defun

And now for the asynchronous variants.

@defun magit-run-git-async &rest args

Start Git, prepare for refresh, and return the process object.
ARGS is flattened and then used as arguments to Git.

Display the command line arguments in the echo area.

After Git returns some buffers are refreshed: the buffer that was
current when this function was called (if it is a Magit buffer and
still alive), as well as the respective Magit status buffer.
Unmodified buffers visiting files that are tracked in the current
repository are reverted if @code{magit-revert-buffers} is non-nil.
@end defun

@defun magit-run-git-with-editor &rest args

Export GIT@math{_EDITOR} and start Git.  Also prepare for refresh and
return the process object.  ARGS is flattened and then used as
arguments to Git.

Display the command line arguments in the echo area.

After Git returns some buffers are refreshed: the buffer that was
current when this function was called (if it is a Magit buffer and
still alive), as well as the respective Magit status buffer.
@end defun

@defun magit-start-git &rest args

Start Git, prepare for refresh, and return the process object.

If INPUT is non-nil, it has to be a buffer or the name of an
existing buffer.  The buffer content becomes the processes
standard input.

Option @code{magit-git-executable} specifies the Git executable and option
@code{magit-git-global-arguments} specifies constant arguments.  The
remaining arguments ARGS specify arguments to Git.  They are
flattened before use.

After Git returns, some buffers are refreshed: the buffer that was
current when this function was called (if it is a Magit buffer and
still alive), as well as the respective Magit status buffer.
Unmodified buffers visiting files that are tracked in the current
repository are reverted if @code{magit-revert-buffers} is non-nil.
@end defun

@defun magit-start-process &rest args

Start PROGRAM, prepare for refresh, and return the process object.

If optional argument INPUT is non-nil, it has to be a buffer or
the name of an existing buffer.  The buffer content becomes the
processes standard input.

The process is started using @code{start-file-process} and then setup to
use the sentinel @code{magit-process-sentinel} and the filter
@code{magit-process-filter}.  Information required by these functions is
stored in the process object.  When this function returns the
process has not started to run yet so it is possible to override the
sentinel and filter.

After the process returns, @code{magit-process-sentinel} refreshes the
buffer that was current when @code{magit-start-process} was called (if it
is a Magit buffer and still alive), as well as the respective Magit
status buffer.  Unmodified buffers visiting files that are tracked
in the current repository are reverted if @code{magit-revert-buffers} is
non-nil.
@end defun

@defvar magit-this-process

The child process which is about to start.  This can be used to
change the filter and sentinel.
@end defvar

@defvar magit-process-raise-error

When this is non-nil, then @code{magit-process-sentinel} raises an error if
git exits with a non-zero exit status.  For debugging purposes.
@end defvar

@node Section Plumbing
@section Section Plumbing

@menu
* Creating Sections::
* Section Selection::
* Matching Sections::
@end menu

@node Creating Sections
@subsection Creating Sections

@defmac magit-insert-section &rest args

Insert a section at point.

TYPE is the section type, a symbol.  Many commands that act on the
current section behave differently depending on that type.  Also if
a variable @code{magit-TYPE-section-map} exists, then use that as the
text-property @code{keymap} of all text belonging to the section (but this
may be overwritten in subsections).  TYPE can also have the form
@code{(eval FORM)} in which case FORM is evaluated at runtime.

Optional VALUE is the value of the section, usually a string that is
required when acting on the section.

When optional HIDE is non-nil collapse the section body by default,
i.e. when first creating the section, but not when refreshing the
buffer.  Otherwise, expand it by default.  This can be overwritten using
@code{magit-section-set-visibility-hook}.  When a section is recreated
during a refresh, then the visibility of predecessor is inherited
and HIDE is ignored (but the hook is still honored).

BODY is any number of forms that actually insert the section's
heading and body.  Optional NAME, if specified, has to be a symbol,
which is then bound to the struct of the section being inserted.

Before BODY is evaluated the @code{start} of the section object is set to
the value of @code{point} and after BODY was evaluated its @code{end} is set to
the new value of @code{point}; BODY is responsible for moving @code{point}
forward.

If it turns out inside BODY that the section is empty, then
@code{magit-cancel-section} can be used to abort and remove all traces of
the partially inserted section.  This can happen when creating a
section by washing Git's output and Git didn't actually output
anything this time around.
@end defmac

@defun magit-insert-heading &rest args

Insert the heading for the section currently being inserted.

This function should only be used inside @code{magit-insert-section}.

When called without any arguments, then just set the @code{content} slot of
the object representing the section being inserted to a marker at
@code{point}.  The section should only contain a single line when this
function is used like this.

When called with arguments ARGS, which have to be strings, then
insert those strings at point.  The section should not contain any
text before this happens and afterwards it should again only contain
a single line.  If the @code{face} property is set anywhere inside any of
these strings, then insert all of them unchanged.  Otherwise use the
@code{magit-section-heading} face for all inserted text.

The @code{content} property of the section struct is the end of the heading
(which lasts from @code{start} to @code{content}) and the beginning of the body
(which lasts from @code{content} to @code{end}).  If the value of @code{content} is nil,
then the section has no heading and its body cannot be collapsed.
If a section does have a heading then its height must be exactly one
line, including a trailing newline character.  This isn't enforced;
you are responsible for getting it right.  The only exception is
that this function does insert a newline character if necessary.
@end defun

@defun magit-cancel-section

Cancel the section currently being inserted.  This exits the
innermost call to @code{magit-insert-section} and removes all traces of
what has already happened inside that call.
@end defun

@defun magit-define-section-jumper sym title &optional value

Define an interactive function to go to section SYM@.  TITLE is the
displayed title of the section.
@end defun

@node Section Selection
@subsection Section Selection

@defun magit-current-section

Return the section at point.
@end defun

@defun magit-region-sections &optional condition multiple

Return a list of the selected sections.

When the region is active and constitutes a valid section
selection, then return a list of all selected sections.  This is
the case when the region begins in the heading of a section and
ends in the heading of the same section or in that of a sibling
section.  If optional MULTIPLE is non-nil, then the region cannot
begin and end in the same section.

When the selection is not valid, then return nil.  In this case,
most commands that can act on the selected sections will instead
act on the section at point.

When the region looks like it would in any other buffer then
the selection is invalid.  When the selection is valid then the
region uses the @code{magit-section-highlight} face.  This does not
apply to diffs where things get a bit more complicated, but even
here if the region looks like it usually does, then that's not
a valid selection as far as this function is concerned.

If optional CONDITION is non-nil, then the selection not only
has to be valid; all selected sections additionally have to match
CONDITION, or nil is returned.  See @code{magit-section-match} for the
forms CONDITION can take.
@end defun

@defun magit-region-values &optional condition multiple

Return a list of the values of the selected sections.

Return the values that themselves would be returned by
@code{magit-region-sections} (which see).
@end defun

@node Matching Sections
@subsection Matching Sections

@table @asis
@kindex M-x magit-describe-section-briefly
@cindex magit-describe-section-briefly
@item @kbd{M-x magit-describe-section-briefly} @tie{}@tie{}@tie{}@tie{}(@code{magit-describe-section-briefly})

Show information about the section at point.  This command is
intended for debugging purposes.

@end table

@defun magit-section-ident section

Return an unique identifier for SECTION@.  The return value has the
form @code{((TYPE . VALUE)...)}.
@end defun

@defun magit-get-section ident &optional root

Return the section identified by IDENT@.  IDENT has to be a list as
returned by @code{magit-section-ident}.
@end defun

@defun magit-section-match condition &optional section

Return @code{t} if SECTION matches CONDITION@.
SECTION defaults to the section at point.  If SECTION is not
specified and there also is no section at point, then return
@code{nil}.

CONDITION can take the following forms:
@itemize
@item
@code{(CONDITION...)}

matches if any of the CONDITIONs matches.


@item
@code{[CLASS...]}

matches if the section's class is the same
as the first CLASS or a subclass of that;
the section's parent class matches the
second CLASS; and so on.


@item
@code{[* CLASS...]}

matches sections that match @code{[CLASS...]} and
also recursively all their child sections.


@item
@code{CLASS}

matches if the section's class is the same
as CLASS or a subclass of that; regardless
of the classes of the parent sections.
@end itemize

Each CLASS should be a class symbol, identifying a class that
derives from @code{magit-section}.  For backward compatibility CLASS
can also be a "type symbol".  A section matches such a symbol
if the value of its @code{type} slot is @code{eq}.  If a type symbol has
an entry in @code{magit--section-type-alist}, then a section also
matches that type if its class is a subclass of the class that
corresponds to the type as per that alist.

Note that it is not necessary to specify the complete section
lineage as printed by @code{magit-describe-section-briefly}, unless
of course you want to be that precise.
@end defun

@defun magit-section-value-if condition &optional section

If the section at point matches CONDITION, then return its value.

If optional SECTION is non-nil then test whether that matches
instead.  If there is no section at point and SECTION is nil,
then return nil.  If the section does not match, then return
nil.

See @code{magit-section-match} for the forms CONDITION can take.
@end defun

@defun magit-section-case &rest clauses

Choose among clauses on the type of the section at point.

Each clause looks like (CONDITION BODY@dots{}).  The type of the
section is compared against each CONDITION; the BODY forms of the
first match are evaluated sequentially and the value of the last
form is returned.  Inside BODY the symbol @code{it} is bound to the
section at point.  If no clause succeeds or if there is no
section at point return nil.

See @code{magit-section-match} for the forms CONDITION can take.
Additionally a CONDITION of t is allowed in the final clause and
matches if no other CONDITION match, even if there is no section at
point.
@end defun

@defvar magit-root-section

The root section in the current buffer.  All other sections are
descendants of this section.  The value of this variable is set by
@code{magit-insert-section} and you should never modify it.
@end defvar

For diff related sections a few additional tools exist.

@defun magit-diff-type &optional section

Return the diff type of SECTION@.

The returned type is one of the symbols @code{staged}, @code{unstaged}, @code{committed},
or @code{undefined}.  This type serves a similar purpose as the general
type common to all sections (which is stored in the @code{type} slot of the
corresponding @code{magit-section} struct) but takes additional information
into account.  When the SECTION isn't related to diffs and the
buffer containing it also isn't a diff-only buffer, then return nil.

Currently the type can also be one of @code{tracked} and @code{untracked}, but
these values are not handled explicitly in every place they should
be.  A possible fix could be to just return nil here.

The section has to be a @code{diff} or @code{hunk} section, or a section whose
children are of type @code{diff}.  If optional SECTION is nil, return the
diff type for the current section.  In buffers whose major mode is
@code{magit-diff-mode} SECTION is ignored and the type is determined using
other means.  In @code{magit-revision-mode} buffers the type is always
@code{committed}.
@end defun

@defun magit-diff-scope &optional section strict

Return the diff scope of SECTION or the selected section(s).

A diff's "scope" describes what part of a diff is selected, it is a
symbol, one of @code{region}, @code{hunk}, @code{hunks}, @code{file}, @code{files}, or @code{list}.  Do not
confuse this with the diff "type", as returned by @code{magit-diff-type}.

If optional SECTION is non-nil, then return the scope of that,
ignoring the sections selected by the region.  Otherwise return the
scope of the current section, or if the region is active and selects
a valid group of diff related sections, the type of these sections,
i.e. @code{hunks} or @code{files}.  If SECTION (or if the current section that
is nil) is a @code{hunk} section and the region starts and ends inside
the body of a that section, then the type is @code{region}.

If optional STRICT is non-nil then return nil if the diff type of
the section at point is @code{untracked} or the section at point is not
actually a @code{diff} but a @code{diffstat} section.
@end defun

@node Refreshing Buffers
@section Refreshing Buffers

All commands that create a new Magit buffer or change what is being
displayed in an existing buffer do so by calling @code{magit-mode-setup}.
Among other things, that function sets the buffer local values of
@code{default-directory} (to the top-level of the repository),
@code{magit-refresh-function}, and @code{magit-refresh-args}.

Buffers are refreshed by calling the function that is the local value
of @code{magit-refresh-function} (a function named @code{magit-*-refresh-buffer},
where @code{*} may be something like @code{diff}) with the value of
@code{magit-refresh-args} as arguments.

@defmac magit-mode-setup buffer switch-func mode refresh-func &optional refresh-args

This function displays and selects BUFFER, turns on MODE, and
refreshes a first time.

This function displays and optionally selects BUFFER by calling
@code{magit-mode-display-buffer} with BUFFER, MODE and SWITCH-FUNC as
arguments.  Then it sets the local value of @code{magit-refresh-function}
to REFRESH-FUNC and that of @code{magit-refresh-args} to REFRESH-ARGS@.
Finally it creates the buffer content by calling REFRESH-FUNC with
REFRESH-ARGS as arguments.

All arguments are evaluated before switching to BUFFER@.
@end defmac

@defun magit-mode-display-buffer buffer mode &optional switch-function

This function display BUFFER in some window and select it.  BUFFER
may be a buffer or a string, the name of a buffer.  The buffer is
returned.

Unless BUFFER is already displayed in the selected frame, store the
previous window configuration as a buffer local value, so that it
can later be restored by @code{magit-mode-bury-buffer}.

The buffer is displayed and selected using SWITCH-FUNCTION@.  If that
is @code{nil} then @code{pop-to-buffer} is used if the current buffer's major mode
derives from @code{magit-mode}.  Otherwise @code{switch-to-buffer} is used.
@end defun

@defvar magit-refresh-function

The value of this buffer-local variable is the function used to
refresh the current buffer.  It is called with @code{magit-refresh-args} as
arguments.
@end defvar

@defvar magit-refresh-args

The list of arguments used by @code{magit-refresh-function} to refresh the
current buffer.  @code{magit-refresh-function} is called with these
arguments.

The value is usually set using @code{magit-mode-setup}, but in some cases
it's also useful to provide commands that can change the value.  For
example, the @code{magit-diff-refresh} transient can be used to change any
of the arguments used to display the diff, without having to specify
again which differences should be shown, but @code{magit-diff-more-context},
@code{magit-diff-less-context} and @code{magit-diff-default-context} change just
the @code{-U<N>} argument.  In both case this is done by changing the value
of this variable and then calling this @code{magit-refresh-function}.
@end defvar

@node Conventions
@section Conventions

Also see @ref{Completion and Confirmation}.

@menu
* Theming Faces::
@end menu

@node Theming Faces
@subsection Theming Faces

The default theme uses blue for local branches, green for remote
branches, and goldenrod (brownish yellow) for tags.  When creating a
new theme, you should probably follow that example.  If your theme
already uses other colors, then stick to that.

In older releases these reference faces used to have a background
color and a box around them.  The basic default faces no longer do so,
to make Magit buffers much less noisy, and you should follow that
example at least with regards to boxes.  (Boxes were used in the past
to work around a conflict between the highlighting overlay and text
property backgrounds.  That's no longer necessary because highlighting no
longer causes other background colors to disappear.)  Alternatively
you can keep the background color and/or box, but then have to take
special care to adjust @code{magit-branch-current} accordingly.  By default
it looks mostly like @code{magit-branch-local}, but with a box (by default
the former is the only face that uses a box, exactly so that it sticks
out).  If the former also uses a box, then you have to make sure that
it differs in some other way from the latter.

The most difficult faces to theme are those related to diffs,
headings, highlighting, and the region.  There are faces that fall
into all four groups - expect to spend some time getting this right.

The @code{region} face in the default theme, in both the light and dark
variants, as well as in many other themes, distributed with Emacs or
by third-parties, is very ugly.  It is common to use a background
color that really sticks out, which is ugly but if that were the only
problem then it would be acceptable.  Unfortunately many themes also
set the foreground color, which ensures that all text within the
region is readable.  Without doing that there might be cases where
some foreground color is too close to the region background color to
still be readable.  But it also means that text within the region
loses all syntax highlighting.

I consider the work that went into getting the @code{region} face right to be
a good indicator for the general quality of a theme.  My
recommendation for the @code{region} face is this: use a background color
slightly different from the background color of the @code{default} face, and
do not set the foreground color at all.  So for a light theme you
might use a light (possibly tinted) gray as the background color of
@code{default} and a somewhat darker gray for the background of @code{region}.
That should usually be enough to not collide with the foreground color
of any other face.  But if some other faces also set a light gray as
background color, then you should also make sure it doesn't collide
with those (in some cases it might be acceptable though).

Magit only uses the @code{region} face when the region is "invalid" by its
own definition.  In a Magit buffer the region is used to either select
multiple sibling sections, so that commands which support it act on
all of these sections instead of just the current section, or to
select lines within a single hunk section.  In all other cases, the
section is considered invalid and Magit won't act on it.  But such
invalid sections happen, either because the user has not moved point
enough yet to make it valid or because she wants to use a non-magit
command to act on the region, e.g. @code{kill-region}.

So using the regular @code{region} face for invalid sections is a feature.  It
tells the user that Magit won't be able to act on it.  It's acceptable
if that face looks a bit odd and even (but less so) if it collides
with the background colors of section headings and other things that
have a background color.

Magit highlights the current section.  If a section has subsections,
then all of them are highlighted.  This is done using faces that have
"highlight" in their names.  For most sections, @code{magit-section-highlight}
is used for both the body and the heading.  Like the @code{region} face, it
should only set the background color to something similar to that of
@code{default}.  The highlight background color must be different from both
the @code{region} background color and the @code{default} background color.

For diff related sections Magit uses various faces to
highlight different parts of the selected section(s).  Note that hunk
headings, unlike all other section headings, by default have a
background color, because it is useful to have very visible separators
between hunks.  That face @code{magit-diff-hunk-heading}, should be different
from both @code{magit-diff-hunk-heading-highlight} and
@code{magit-section-highlight}, as well as from @code{magit-diff-context} and
@code{magit-diff-context-highlight}.  By default we do that by changing the
foreground color.  Changing the background color would lead to
complications, and there are already enough we cannot get around.
(Also note that it is generally a good idea for section headings to
always be bold, but only for sections that have subsections).

When there is a valid region selecting diff-related sibling sections,
i.e. multiple files or hunks, then the bodies of all these sections
use the respective highlight faces, but additionally the headings
instead use one of the faces @code{magit-diff-file-heading-selection} or
@code{magit-diff-hunk-heading-selection}.  These faces have to be different
from the regular highlight variants to provide explicit visual
indication that the region is active.

When theming diff related faces, start by setting the option
@code{magit-diff-refine-hunk} to @code{all}.  You might personally prefer to only
refine the current hunk or not use hunk refinement at all, but some of
the users of your theme want all hunks to be refined, so you have to
cater to that.

(Also turn on @code{magit-diff-highlight-indentation},
@code{magit-diff-highlight-trailing}, and @code{magit-diff-paint-whitespace}; and
insert some whitespace errors into the code you use for testing.)

For e.g. "added lines" you have to adjust three faces:
@code{magit-diff-added}, @code{magit-diff-added-highlight}, and
@code{smerge-refined-added}.  Make sure that the latter works well with both
of the former, as well as @code{smerge-other} and @code{diff-added}.  Then do the
same for the removed lines, context lines, lines added by us, and
lines added by them.  Also make sure the respective added, removed,
and context faces use approximately the same saturation for both the
highlighted and unhighlighted variants.  Also make sure the file and
diff headings work nicely with context lines (e.g. make them look
different).  Line faces should set both the foreground and the
background color.  For example, for added lines use two different
greens.

It's best if the foreground color of both the highlighted and the
unhighlighted variants are the same, so you will need to have to find
a color that works well on the highlight and unhighlighted background,
the refine background, and the highlight context background.  When
there is an hunk internal region, then the added- and removed-lines
background color is used only within that region.  Outside the region
the highlighted context background color is used.  This makes it
easier to see what is being staged.  With an hunk internal region the
hunk heading is shown using @code{magit-diff-hunk-heading-selection}, and so
are the thin lines that are added around the lines that fall within
the region.  The background color of that has to be distinct enough
from the various other involved background colors.

Nobody said this would be easy.  If your theme restricts itself to a
certain set of colors, then you should make an exception here.
Otherwise it would be impossible to make the diffs look good in each
and every variation.  Actually you might want to just stick to the
default definitions for these faces.  You have been warned.  Also
please note that if you do not get this right, this will in some cases
look to users like bugs in Magit - so please do it right or not at
all.

@node FAQ
@appendix FAQ

The next two nodes lists frequently asked questions.  For a list of
frequently @strong{and recently} asked questions, i.e. questions that haven't
made it into the manual yet, see
@uref{https://github.com/magit/magit/wiki/FAQ}.

Please also use the @ref{Debugging Tools}.

@menu
* FAQ - How to @dots{}?::
* FAQ - Issues and Errors::
@end menu

@node FAQ - How to @dots{}?
@appendixsec FAQ - How to @dots{}?

@menu
* How to show git's output?::
* How to install the gitman info manual?::
* How to show diffs for gpg-encrypted files?::
* How does branching and pushing work?::
* Can Magit be used as @code{ediff-version-control-package}?::
@end menu

@node How to show git's output?
@appendixsubsec How to show git's output?

To show the output of recently run git commands, press @code{$} (or, if that
isn't available, @code{M-x magit-process-buffer}).  This will show a buffer
containing a section per git invocation; as always press @code{TAB} to expand
or collapse them.

By default, git's output is only inserted into the process buffer if it
is run for side-effects.  When the output is consumed in some way,
also inserting it into the process buffer would be too expensive.  For
debugging purposes, it's possible to do so anyway by setting
@code{magit-git-debug} to @code{t}.

@node How to install the gitman info manual?
@appendixsubsec How to install the gitman info manual?

Git's manpages can be exported as an info manual called @code{gitman}.
Magit's own info manual links to nodes in that manual instead of the
actual manpages because Info doesn't support linking to manpages.

Unfortunately some distributions do not install the @code{gitman} manual by
default and you will have to install a separate documentation package
to get it.

Magit patches Info adding the ability to visit links to the @code{gitman}
Info manual by instead viewing the respective manpage.  If you prefer
that approach, then set the value of @code{magit-view-git-manual-method} to
one of the supported packages @code{man} or @code{woman}, e.g.:

@lisp
(setq magit-view-git-manual-method 'man)
@end lisp

@node How to show diffs for gpg-encrypted files?
@appendixsubsec How to show diffs for gpg-encrypted files?

Git supports showing diffs for encrypted files, but has to be told to
do so.  Since Magit just uses Git to get the diffs, configuring Git
also affects the diffs displayed inside Magit.

@example
git config --global diff.gpg.textconv "gpg --no-tty --decrypt"
echo "*.gpg filter=gpg diff=gpg" > .gitattributes
@end example

@node How does branching and pushing work?
@appendixsubsec How does branching and pushing work?

Please see @ref{Branching} and @uref{http://emacsair.me/2016/01/18/magit-2.4}

@node Can Magit be used as @code{ediff-version-control-package}?
@appendixsubsec Can Magit be used as @code{ediff-version-control-package}?

No, it cannot.  For that to work the functions @code{ediff-magit-internal}
and @code{ediff-magit-merge-internal} would have to be implemented, and they
are not.  These two functions are only used by the three commands
@code{ediff-revision}, @code{ediff-merge-revisions-with-ancestor}, and
@code{ediff-merge-revisions}.

These commands only delegate the task of populating buffers with
certain revisions to the "internal" functions.  The equally important
task of determining which revisions are to be compared/merged is not
delegated.  Instead this is done without any support whatsoever from
the version control package/system - meaning that the user has to
enter the revisions explicitly.  Instead of implementing
@code{ediff-magit-internal} we provide @code{magit-ediff-compare}, which handles
both tasks like it is 2005.

The other commands @code{ediff-merge-revisions} and
@code{ediff-merge-revisions-with-ancestor} are normally not what you want
when using a modern version control system like Git.  Instead of
letting the user resolve only those conflicts which Git could not
resolve on its own, they throw away all work done by Git and then
expect the user to manually merge all conflicts, including those that
had already been resolved.  That made sense back in the days when
version control systems couldn't merge (or so I have been told), but
not anymore.  Once in a blue moon you might actually want to see all
conflicts, in which case you @strong{can} use these commands, which then use
@code{ediff-vc-merge-internal}.  So we don't actually have to implement
@code{ediff-magit-merge-internal}.  Instead we provide the more useful
command @code{magit-ediff-resolve} which only shows yet-to-be resolved
conflicts.

@node FAQ - Issues and Errors
@appendixsec FAQ - Issues and Errors

@menu
* Magit is slow::
* I changed several thousand files at once and now Magit is unusable::
* I am having problems committing::
* I am using MS Windows and cannot push with Magit::
* I am using OS X and SOMETHING works in shell, but not in Magit: I am using OS X and SOMETHING works in shell but not in Magit. 
* Expanding a file to show the diff causes it to disappear::
* Point is wrong in the @code{COMMIT_EDITMSG} buffer::
* The mode-line information isn't always up-to-date::
* A branch and tag sharing the same name breaks SOMETHING::
* My Git hooks work on the command-line but not inside Magit::
* @code{git-commit-mode} isn't used when committing from the command-line::
* Point ends up inside invisible text when jumping to a file-visiting buffer::
@end menu

@node Magit is slow
@appendixsubsec Magit is slow

See @ref{Performance}.

@node I changed several thousand files at once and now Magit is unusable
@appendixsubsec I changed several thousand files at once and now Magit is unusable

Magit is @strong{currently} not expected to work under such conditions. It sure
would be nice if it did, and v2.5 will hopefully be a big step into
that direction.  But it might take until v3.1 to accomplish fully
satisfactory performance, because that requires some heavy refactoring.

But for now we recommend you use the command line to complete this one
commit.  Also see @ref{Performance}.

@node I am having problems committing
@appendixsubsec I am having problems committing

That likely means that Magit is having problems finding an appropriate
emacsclient executable.  See @ref{Configuring With-Editor,,,with-editor,}
and @ref{Debugging,,,with-editor,}.

@node I am using MS Windows and cannot push with Magit
@appendixsubsec I am using MS Windows and cannot push with Magit

It's almost certain that Magit is only incidental to this issue.  It
is much more likely that this is a configuration issue, even if you
can push on the command line.

Detailed setup instructions can be found at
@uref{https://github.com/magit/magit/wiki/Pushing-with-Magit-from-Windows}.

@node I am using OS X and SOMETHING works in shell but not in Magit
@appendixsubsec I am using OS X and SOMETHING works in shell, but not in Magit

This usually occurs because Emacs doesn't have the same environment
variables as your shell.  Try installing and configuring
@uref{https://github.com/purcell/exec-path-from-shell}.  By default it
synchronizes @code{$PATH}, which helps Magit find the same @code{git} as the one you
are using on the shell.

If SOMETHING is "passphrase caching with gpg-agent for commit and/or
tag signing", then you'll also need to synchronize @code{$GPG_AGENT_INFO}.

@node Expanding a file to show the diff causes it to disappear
@appendixsubsec Expanding a file to show the diff causes it to disappear

This is probably caused by a change of a @code{diff.*} Git variable.  You
probably set that variable for a reason, and should therefore
only undo that setting in Magit by customizing
@code{magit-git-global-arguments}.

@node Point is wrong in the @code{COMMIT_EDITMSG} buffer
@appendixsubsec Point is wrong in the @code{COMMIT_EDITMSG} buffer

Neither Magit nor `git-commit` fiddle with point in the buffer used to
write commit messages, so something else must be doing it.

You have probably globally enabled a mode which does restore point in
file-visiting buffers.  It might be a bit surprising, but when you
write a commit message, then you are actually editing a file.

So you have to figure out which package is doing.  @code{saveplace},
@code{pointback}, and @code{session} are likely candidates.  These snippets might
help:

@lisp
(setq session-name-disable-regexp "\\(?:\\`'\\.git/[A-Z_]+\\'\\)")

(with-eval-after-load 'pointback
  (lambda ()
    (when (or git-commit-mode git-rebase-mode)
      (pointback-mode -1))))
@end lisp

@node The mode-line information isn't always up-to-date
@appendixsubsec The mode-line information isn't always up-to-date

Magit is not responsible for the version control information that is
being displayed in the mode-line and looks something like @code{Git-master}.
The built-in "Version Control" package, also known as "VC", updates
that information, and can be told to do so more often:

@lisp
(setq auto-revert-check-vc-info t)
@end lisp

But doing so isn't good for performance.  For more (overly optimistic)
information see @ref{VC Mode Line,,,emacs,}.

If you don't really care about seeing that information in the
mode-line, but just don't want to see @emph{incorrect} information, then
consider disabling VC when using Git:

@lisp
(setq vc-handled-backends (delq 'Git vc-handled-backends))
@end lisp

Or to disable it completely:

@lisp
(setq vc-handled-backends nil)
@end lisp

@node A branch and tag sharing the same name breaks SOMETHING
@appendixsubsec A branch and tag sharing the same name breaks SOMETHING

Or more generally, ambiguous refnames break SOMETHING@.

Magit assumes that refs are named non-ambiguously across the
"refs/heads/", "refs/tags/", and "refs/remotes/" namespaces (i.e., all
the names remain unique when those prefixes are stripped).  We
consider ambiguous refnames unsupported and recommend that you use a
non-ambiguous naming scheme.  However, if you do work with a
repository that has ambiguous refnames, please report any issues you
encounter so that we can investigate whether there is a simple fix.

@node My Git hooks work on the command-line but not inside Magit
@appendixsubsec My Git hooks work on the command-line but not inside Magit

When Magit calls @code{git} it adds a few global arguments including
@code{--literal-pathspecs} and the @code{git} process started by Magit then passes
that setting on to other @code{git} process it starts itself.  It does so by
setting the environment variable @code{GIT_LITERAL_PATHSPECS}, not by calling
subprocesses with the @code{--literal-pathspecs} argument.  You can therefore
override this setting in hook scripts using @code{unset
GIT_LITERAL_PATHSPECS}.

@node @code{git-commit-mode} isn't used when committing from the command-line
@appendixsubsec @code{git-commit-mode} isn't used when committing from the command-line

The reason for this is that @code{git-commit.el} has not been loaded yet
and/or that the server has not been started yet.  These things have
always already been taken care of when you commit from Magit because
in order to do so, Magit has to be loaded and doing that involves
loading @code{git-commit} and starting the server.

If you want to commit from the command-line, then you have to take
care of these things yourself. Your @code{init.el} file should contain:

@lisp
(require 'git-commit)
(server-mode)
@end lisp

Instead of `(require 'git-commit)` you may also use:

@lisp
(load "/path/to/magit-autoloads.el")
@end lisp

You might want to do that because loading @code{git-commit} causes large
parts of Magit to be loaded.

There are also some variations of @code{(server-mode)} that you might want to
try. Personally I use:

@lisp
(use-package server
  :config (or (server-running-p) (server-mode)))
@end lisp

Now you can use:

@example
$ emacs&
$ EDITOR=emacsclient git commit
@end example

However you cannot use:

@example
$ killall emacs
$ EDITOR="emacsclient --alternate-editor emacs" git commit
@end example

This will actually end up using @code{emacs}, not @code{emacsclient}.  If you do
this, then can still edit the commit message but @code{git-commit-mode} won't
be used and you have to exit @code{emacs} to finish the process.

Tautology ahead.  If you want to be able to use @code{emacsclient} to connect
to a running @code{emacs} instance, even though no @code{emacs} instance is running,
then you cannot use @code{emacsclient} directly.

Instead you have to create a script that does something like this:

Try to use @code{emacsclient} (without using @code{--alternate-editor}).  If that
succeeds, do nothing else.  Otherwise start @code{emacs &} (and @code{init.el} must
call @code{server-start}) and try to use @code{emacsclient} again.

@node Point ends up inside invisible text when jumping to a file-visiting buffer
@appendixsubsec Point ends up inside invisible text when jumping to a file-visiting buffer

This can happen when you type @code{RET} on a hunk to visit the respective
file at the respective position.  One solution to this problem is to
use @code{global-reveal-mode}.  It makes sure that text around point is
always visible.  If that is too drastic for your taste, then you may
instead use @code{magit-diff-visit-file-hook} to reveal the text, possibly
using @code{reveal-post-command} or for Org buffers @code{org-reveal}.

@node Debugging Tools
@chapter Debugging Tools

Magit and its dependencies provide a few debugging tools, and we
appreciate it very much if you use those tools before reporting an
issue.  Please include all relevant output when reporting an
issue.

@table @asis
@kindex M-x magit-version
@cindex magit-version
@item @kbd{M-x magit-version} @tie{}@tie{}@tie{}@tie{}(@code{magit-version})

This command shows the currently used versions of Magit, Git, and
Emacs in the echo area.  Non-interactively this just returns the
Magit version.

@kindex M-x magit-emacs-Q-command
@cindex magit-emacs-Q-command
@item @kbd{M-x magit-emacs-Q-command} @tie{}@tie{}@tie{}@tie{}(@code{magit-emacs-Q-command})

This command shows a debugging shell command in the echo area and
adds it to the kill ring.  Paste that command into a shell and run
it.

This shell command starts @code{emacs} with only @code{magit} and its
dependencies loaded.  Neither your configuration nor other installed
packages are loaded.  This makes it easier to determine whether some
issue lays with Magit or something else.

If you run Magit from its Git repository, then you should be able to
use @code{make emacs-Q} instead of the output of this command.

@kindex M-x magit-toggle-verbose-refresh
@cindex magit-toggle-verbose-refresh
@item @kbd{M-x magit-toggle-verbose-refresh} @tie{}@tie{}@tie{}@tie{}(@code{magit-toggle-verbose-refresh})

This command toggles whether Magit refreshes buffers verbosely.
Enabling this helps figuring out which sections are bottlenecks.
The additional output can be found in the @code{*Messages*} buffer.

@kindex M-x magit-debug-git-executable
@cindex magit-debug-git-executable
@item @kbd{M-x magit-debug-git-executable} @tie{}@tie{}@tie{}@tie{}(@code{magit-debug-git-executable})

This command displays a buffer containing information about the
available and used @code{git} executable(s), and can be useful when
investigating @code{exec-path} issues.

Also see @ref{Git Executable}.

@kindex M-x with-editor-debug
@cindex with-editor-debug
@item @kbd{M-x with-editor-debug} @tie{}@tie{}@tie{}@tie{}(@code{with-editor-debug})

This command displays a buffer containing information about the
available and used @code{emacsclient} executable(s), and can be useful
when investigating why Magit (or rather @code{with-editor}) cannot find
an appropriate @code{emacsclient} executable.

Also see @ref{Debugging,,,with-editor,}.
@end table

Please also see the @ref{FAQ}.

@node Keystroke Index
@appendix Keystroke Index

@printindex ky

@node Command Index
@appendix Command Index

@printindex cp

@node Function Index
@appendix Function Index

@printindex fn

@node Variable Index
@appendix Variable Index

@printindex vr

@bye