@@ -2306,17 +2306,13 @@ branch and then merge into each of the test and release branches. For
2306
2306
these changes, just apply directly to the "release" branch, and then
2307
2307
merge that into the "test" branch.
2308
2308
2309
- To create diffstat and shortlog summaries of changes to include in a "please
2310
- pull" request to Linus you can use:
2309
+ After pushing your work to `mytree`, you can use
2310
+ linkgit:git-request-pull[1] to prepare a "please pull" request message
2311
+ to send to Linus:
2311
2312
2312
2313
-------------------------------------------------
2313
- $ git diff --stat origin..release
2314
- -------------------------------------------------
2315
-
2316
- and
2317
-
2318
- -------------------------------------------------
2319
- $ git log -p origin..release | git shortlog
2314
+ $ git push mytree
2315
+ $ git request-pull origin mytree release
2320
2316
-------------------------------------------------
2321
2317
2322
2318
Here are some of the scripts that simplify all this even further.
@@ -2557,6 +2553,12 @@ return mywork to the state it had before you started the rebase:
2557
2553
$ git rebase --abort
2558
2554
-------------------------------------------------
2559
2555
2556
+ If you need to reorder or edit a number of commits in a branch, it may
2557
+ be easier to use `git rebase -i`, which allows you to reorder and
2558
+ squash commits, as well as marking them for individual editing during
2559
+ the rebase. See <<interactive-rebase>> for details, and
2560
+ <<reordering-patch-series>> for alternatives.
2561
+
2560
2562
[[rewriting-one-commit]]
2561
2563
Rewriting a single commit
2562
2564
-------------------------
@@ -2570,72 +2572,89 @@ $ git commit --amend
2570
2572
2571
2573
which will replace the old commit by a new commit incorporating your
2572
2574
changes, giving you a chance to edit the old commit message first.
2575
+ This is useful for fixing typos in your last commit, or for adjusting
2576
+ the patch contents of a poorly staged commit.
2573
2577
2574
- You can also use a combination of this and linkgit:git-rebase[1] to
2575
- replace a commit further back in your history and recreate the
2576
- intervening changes on top of it. First, tag the problematic commit
2577
- with
2578
+ If you need to amend commits from deeper in your history, you can
2579
+ use <<interactive-rebase,interactive rebase's `edit` instruction>>.
2578
2580
2579
- -------------------------------------------------
2580
- $ git tag bad mywork~5
2581
- -------------------------------------------------
2582
-
2583
- (Either gitk or `git log` may be useful for finding the commit.)
2581
+ [[reordering-patch-series]]
2582
+ Reordering or selecting from a patch series
2583
+ -------------------------------------------
2584
2584
2585
- Then check out that commit, edit it, and rebase the rest of the series
2586
- on top of it (note that we could check out the commit on a temporary
2587
- branch, but instead we're using a <<detached-head,detached head>>) :
2585
+ Sometimes you want to edit a commit deeper in your history. One
2586
+ approach is to use `git format-patch` to create a series of patches
2587
+ and then reset the state to before the patches :
2588
2588
2589
2589
-------------------------------------------------
2590
- $ git checkout bad
2591
- $ # make changes here and update the index
2592
- $ git commit --amend
2593
- $ git rebase --onto HEAD bad mywork
2590
+ $ git format-patch origin
2591
+ $ git reset --hard origin
2594
2592
-------------------------------------------------
2595
2593
2596
- When you're done, you'll be left with mywork checked out, with the top
2597
- patches on mywork reapplied on top of your modified commit. You can
2598
- then clean up with
2594
+ Then modify, reorder, or eliminate patches as needed before applying
2595
+ them again with linkgit:git-am[1]:
2599
2596
2600
2597
-------------------------------------------------
2601
- $ git tag -d bad
2598
+ $ git am *.patch
2602
2599
-------------------------------------------------
2603
2600
2604
- Note that the immutable nature of git history means that you haven't really
2605
- "modified" existing commits; instead, you have replaced the old commits with
2606
- new commits having new object names.
2601
+ [[interactive-rebase]]
2602
+ Using interactive rebases
2603
+ -------------------------
2607
2604
2608
- [[reordering- patch- series]]
2609
- Reordering or selecting from a patch series
2610
- -------------------------------------------
2605
+ You can also edit a patch series with an interactive rebase. This is
2606
+ the same as <<reordering-patch-series,reordering a patch series using
2607
+ `format-patch`>>, so use whichever interface you like best.
2611
2608
2612
- Given one existing commit, the linkgit:git-cherry-pick[1] command
2613
- allows you to apply the change introduced by that commit and create a
2614
- new commit that records it. So, for example, if "mywork" points to a
2615
- series of patches on top of "origin", you might do something like:
2609
+ Rebase your current HEAD on the last commit you want to retain as-is.
2610
+ For example, if you want to reorder the last 5 commits, use:
2616
2611
2617
2612
-------------------------------------------------
2618
- $ git checkout -b mywork-new origin
2619
- $ gitk origin..mywork &
2613
+ $ git rebase -i HEAD~5
2620
2614
-------------------------------------------------
2621
2615
2622
- and browse through the list of patches in the mywork branch using gitk,
2623
- applying them (possibly in a different order) to mywork-new using
2624
- cherry-pick, and possibly modifying them as you go using `git commit --amend`.
2625
- The linkgit:git-gui[1] command may also help as it allows you to
2626
- individually select diff hunks for inclusion in the index (by
2627
- right-clicking on the diff hunk and choosing "Stage Hunk for Commit").
2628
-
2629
- Another technique is to use `git format-patch` to create a series of
2630
- patches, then reset the state to before the patches:
2616
+ This will open your editor with a list of steps to be taken to perform
2617
+ your rebase.
2631
2618
2632
2619
-------------------------------------------------
2633
- $ git format-patch origin
2634
- $ git reset --hard origin
2635
- -------------------------------------------------
2620
+ pick deadbee The oneline of this commit
2621
+ pick fa1afe1 The oneline of the next commit
2622
+ ...
2636
2623
2637
- Then modify, reorder, or eliminate patches as preferred before applying
2638
- them again with linkgit:git-am[1].
2624
+ # Rebase c0ffeee..deadbee onto c0ffeee
2625
+ #
2626
+ # Commands:
2627
+ # p, pick = use commit
2628
+ # r, reword = use commit, but edit the commit message
2629
+ # e, edit = use commit, but stop for amending
2630
+ # s, squash = use commit, but meld into previous commit
2631
+ # f, fixup = like "squash", but discard this commit's log message
2632
+ # x, exec = run command (the rest of the line) using shell
2633
+ #
2634
+ # These lines can be re-ordered; they are executed from top to bottom.
2635
+ #
2636
+ # If you remove a line here THAT COMMIT WILL BE LOST.
2637
+ #
2638
+ # However, if you remove everything, the rebase will be aborted.
2639
+ #
2640
+ # Note that empty commits are commented out
2641
+ -------------------------------------------------
2642
+
2643
+ As explained in the comments, you can reorder commits, squash them
2644
+ together, edit commit messages, etc. by editing the list. Once you
2645
+ are satisfied, save the list and close your editor, and the rebase
2646
+ will begin.
2647
+
2648
+ The rebase will stop where `pick` has been replaced with `edit` or
2649
+ when a step in the list fails to mechanically resolve conflicts and
2650
+ needs your help. When you are done editing and/or resolving conflicts
2651
+ you can continue with `git rebase --continue`. If you decide that
2652
+ things are getting too hairy, you can always bail out with `git rebase
2653
+ --abort`. Even after the rebase is complete, you can still recover
2654
+ the original branch by using the <<reflogs,reflog>>.
2655
+
2656
+ For a more detailed discussion of the procedure and additional tips,
2657
+ see the "INTERACTIVE MODE" section of linkgit:git-rebase[1].
2639
2658
2640
2659
[[patch-series-tools]]
2641
2660
Other tools
@@ -3721,7 +3740,9 @@ module a
3721
3740
3722
3741
NOTE: The changes are still visible in the submodule's reflog.
3723
3742
3724
- This is not the case if you did not commit your changes.
3743
+ If you have uncommitted changes in your submodule working tree, `git
3744
+ submodule update` will not overwrite them. Instead, you get the usual
3745
+ warning about not being able switch from a dirty branch.
3725
3746
3726
3747
[[low-level-operations]]
3727
3748
Low-level git operations
0 commit comments