Skip to content

Commit 6ee2f73

Browse files
committed
Edits part III
1 parent 988ccc2 commit 6ee2f73

File tree

1 file changed

+76
-52
lines changed

1 file changed

+76
-52
lines changed

en/book/03-git-branching/chapter3.asc

Lines changed: 76 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
**TODO**: reword figure titles
2+
13
== Git Branching
24

35
Nearly every VCS has some form of branching support. Branching means you diverge from the main line of development and continue to do work without messing with that main line. In many VCS tools, this is a somewhat expensive process, often requiring you to create a new copy of your source code directory, which can take a long time for large projects.
@@ -271,7 +273,7 @@ It’s worth pointing out that Git determines the best common ancestor to use fo
271273
.Git automatically creates a new commit object that contains the merged work
272274
image::images/18333fig0317-tn.png[Git automatically creates a new commit object that contains the merged work.]
273275

274-
Now that your work is merged in, you have no further need for the `iss53` branch. You can delete it and then close the ticket in your ticket-tracking system:
276+
Now that your work is merged in, you have no further need for the `iss53` branch. You can close the ticket in your ticket-tracking system, and delete the branch:
275277

276278
[source,shell]
277279
----
@@ -295,19 +297,21 @@ Git hasn’t automatically created a new merge commit. It has paused the process
295297
[source,shell]
296298
----
297299
[master*]$ git status
298-
index.html: needs merge
299-
# On branch master
300-
# Changed but not updated:
301-
# (use "git add <file>..." to update what will be committed)
302-
# (use "git checkout -- <file>..." to discard changes in working directory)
303-
#
304-
# unmerged: index.html
305-
#
300+
On branch master
301+
You have unmerged paths.
302+
(fix conflicts and run "git commit")
303+
304+
Unmerged paths:
305+
(use "git add <file>..." to mark resolution)
306+
307+
both modified: index.html
308+
309+
no changes added to commit (use "git add" and/or "git commit -a")
306310
----
307311

308312
Anything that has merge conflicts and hasn’t been resolved is listed as unmerged. Git adds standard conflict-resolution markers to the files that have conflicts, so you can open them manually and resolve those conflicts. Your file contains a section that looks something like this:
309313

310-
[source,shell]
314+
[source,html]
311315
----
312316
<<<<<<< HEAD:index.html
313317
<div id="footer">contact : [email protected]</div>
@@ -318,9 +322,9 @@ Anything that has merge conflicts and hasn’t been resolved is listed as unmerg
318322
>>>>>>> iss53:index.html
319323
----
320324

321-
This means the version in HEAD (your master branch, because that was what you had checked out when you ran your merge command) is the top part of that block (everything above the `=======`), while the version in your `iss53` branch looks like everything in the bottom part. In order to resolve the conflict, you have to either choose one side or the other or merge the contents yourself. For instance, you might resolve this conflict by replacing the entire block with this:
325+
This means the version in `HEAD` (your `master` branch, because that was what you had checked out when you ran your merge command) is the top part of that block (everything above the `=======`), while the version in your `iss53` branch looks like everything in the bottom part. In order to resolve the conflict, you have to either choose one side or the other or merge the contents yourself. For instance, you might resolve this conflict by replacing the entire block with this:
322326

323-
[source,shell]
327+
[source,html]
324328
----
325329
<div id="footer">
326330
please contact us at [email protected]
@@ -333,16 +337,21 @@ If you want to use a graphical tool to resolve these issues, you can run `git me
333337
[source,shell]
334338
----
335339
$ git mergetool
336-
merge tool candidates: kdiff3 tkdiff xxdiff meld gvimdiff opendiff emerge vimdiff
337-
Merging the files: index.html
340+
341+
This message is displayed because 'merge.tool' is not configured.
342+
See 'git mergetool --tool-help' or 'git help config' for more details.
343+
'git mergetool' will now attempt to use one of the following tools:
344+
opendiff kdiff3 tkdiff xxdiff meld tortoisemerge gvimdiff diffuse diffmerge ecmerge p4merge araxis bc3 codecompare vimdiff emerge
345+
Merging:
346+
index.html
338347
339348
Normal merge conflict for 'index.html':
340-
{local}: modified
341-
{remote}: modified
349+
{local}: modified file
350+
{remote}: modified file
342351
Hit return to start merge resolution tool (opendiff):
343352
----
344353

345-
If you want to use a merge tool other than the default (Git chose `opendiff` for me in this case because I ran the command on a Mac), you can see all the supported tools listed at the top after ``merge tool candidates''. Type the name of the tool you’d rather use. In <<_git_tools>>, we’ll discuss how you can change this default value for your environment.
354+
If you want to use a merge tool other than the default (Git chose `opendiff` for me in this case because I ran the command on a Mac), you can see all the supported tools listed at the top after ``one of the following tools.'' Just type the name of the tool you’d rather use. In <<_git_tools>>, we’ll discuss how you can change this default value for your environment (Git gave us a helpful hint).
346355

347356
After you exit the merge tool, Git asks you if the merge was successful. If you tell the script that it was, it stages the file to mark it as resolved for you.
348357

@@ -351,12 +360,13 @@ You can run `git status` again to verify that all conflicts have been resolved:
351360
[source,shell]
352361
----
353362
$ git status
354-
# On branch master
355-
# Changes to be committed:
356-
# (use "git reset HEAD <file>..." to unstage)
357-
#
358-
# modified: index.html
359-
#
363+
On branch master
364+
All conflicts fixed but you are still merging.
365+
(use "git commit" to conclude merge)
366+
367+
Changes to be committed:
368+
369+
modified: index.html
360370
----
361371

362372
If you’re happy with that, and you verify that everything that had conflicts has been staged, you can type `git commit` to finalize the merge commit. The commit message by default looks something like this:
@@ -365,21 +375,34 @@ If you’re happy with that, and you verify that everything that had conflicts h
365375
----
366376
Merge branch 'iss53'
367377
368-
369378
Conflicts:
370-
index.html
379+
index.html
371380
#
372-
# It looks like you may be committing a MERGE.
381+
# It looks like you may be committing a merge.
373382
# If this is not correct, please remove the file
374-
# .git/MERGE_HEAD
383+
# .git/MERGE_HEAD
375384
# and try again.
385+
386+
387+
# Please enter the commit message for your changes. Lines starting
388+
# with '#' will be ignored, and an empty message aborts the commit.
389+
# On branch master
390+
# All conflicts fixed but you are still merging.
391+
#
392+
# Changes to be committed:
393+
# modified: index.html
376394
#
377395
----
378396

379397
You can modify that message with details about how you resolved the merge if you think it would be helpful to others looking at this merge in the future – why you did what you did, if it’s not obvious.
380398

381399
==== Undoing Merges
382400

401+
**TODO**
402+
403+
- `git reset --merge ORIG_HEAD`
404+
- `git revert -m 1 sha`
405+
383406
=== Branch Management
384407

385408
Now that you’ve created, merged, and deleted some branches, let’s look at some branch-management tools that will come in handy when you begin using branches all the time.
@@ -389,27 +412,27 @@ The `git branch` command does more than just create and delete branches. If you
389412
[source,shell]
390413
----
391414
$ git branch
392-
iss53
415+
iss53
393416
* master
394-
testing
417+
testing
395418
----
396419

397420
Notice the `*` character that prefixes the `master` branch: it indicates the branch that you currently have checked out. This means that if you commit at this point, the `master` branch will be moved forward with your new work. To see the last commit on each branch, you can run `git branch -v`:
398421

399422
[source,shell]
400423
----
401424
$ git branch -v
402-
iss53 93b412c fix javascript issue
425+
iss53 93b412c fix javascript issue
403426
* master 7a98805 Merge branch 'iss53'
404-
testing 782fd34 add scott to the author list in the readmes
427+
testing 782fd34 add scott to the author list in the readmes
405428
----
406429

407430
Another useful option to figure out what state your branches are in is to filter this list to branches that you have or have not yet merged into the branch you’re currently on. The useful `--merged` and `--no-merged` options have been available in Git since version 1.5.6 for this purpose. To see which branches are already merged into the branch you’re on, you can run `git branch --merged`:
408431

409432
[source,shell]
410433
----
411434
$ git branch --merged
412-
iss53
435+
iss53
413436
* master
414437
----
415438

@@ -420,15 +443,15 @@ To see all the branches that contain work you haven’t yet merged in, you can r
420443
[source,shell]
421444
----
422445
$ git branch --no-merged
423-
testing
446+
testing
424447
----
425448

426449
This shows your other branch. Because it contains work that isn’t merged in yet, trying to delete it with `git branch -d` will fail:
427450

428451
[source,shell]
429452
----
430453
$ git branch -d testing
431-
error: The branch 'testing' is not an ancestor of your current HEAD.
454+
error: The branch 'testing' is not fully merged.
432455
If you are sure you want to delete it, run 'git branch -D testing'.
433456
----
434457

@@ -518,12 +541,13 @@ If you have a branch named `serverfix` that you want to work on with others, you
518541
[source,shell]
519542
----
520543
$ git push origin serverfix
521-
Counting objects: 20, done.
522-
Compressing objects: 100% (14/14), done.
523-
Writing objects: 100% (15/15), 1.74 KiB, done.
524-
Total 15 (delta 5), reused 0 (delta 0)
544+
Counting objects: 24, done.
545+
Delta compression using up to 8 threads.
546+
Compressing objects: 100% (15/15), done.
547+
Writing objects: 100% (24/24), 1.91 KiB | 0 bytes/s, done.
548+
Total 24 (delta 2), reused 0 (delta 0)
525549
To [email protected]:schacon/simplegit.git
526-
* [new branch] serverfix -> serverfix
550+
* [new branch] serverfix -> serverfix
527551
----
528552

529553
This is a bit of a shortcut. Git automatically expands the `serverfix` branchname out to `refs/heads/serverfix:refs/heads/serverfix`, which means, ``Take my serverfix local branch and push it to update the remote’s serverfix branch.'' We’ll go over the `refs/heads/` part in detail in <<_git_internals>>, but you can generally leave it off. You can also do `git push origin serverfix:serverfix`, which does the same thing – it says, ``Take my serverfix and make it the remote’s serverfix.'' You can use this format to push a local branch into a remote branch that is named differently. If you didn’t want it to be called `serverfix` on the remote, you could instead run `git push origin serverfix:awesomebranch` to push your local `serverfix` branch to the `awesomebranch` branch on the remote project.
@@ -533,12 +557,12 @@ The next time one of your collaborators fetches from the server, they will get a
533557
[source,shell]
534558
----
535559
$ git fetch origin
536-
remote: Counting objects: 20, done.
537-
remote: Compressing objects: 100% (14/14), done.
538-
remote: Total 15 (delta 5), reused 0 (delta 0)
539-
Unpacking objects: 100% (15/15), done.
560+
remote: Counting objects: 7, done.
561+
remote: Compressing objects: 100% (2/2), done.
562+
remote: Total 3 (delta 0), reused 3 (delta 0)
563+
Unpacking objects: 100% (3/3), done.
540564
From [email protected]:schacon/simplegit
541-
* [new branch] serverfix -> origin/serverfix
565+
* [new branch] serverfix -> origin/serverfix
542566
----
543567

544568
It’s important to note that when you do a fetch that brings down new remote branches, you don’t automatically have local, editable copies of them. In other words, in this case, you don’t have a new `serverfix` branch – you only have an `origin/serverfix` pointer that you can’t modify.
@@ -548,8 +572,8 @@ To merge this work into your current working branch, you can run `git merge orig
548572
[source,shell]
549573
----
550574
$ git checkout -b serverfix origin/serverfix
551-
Branch serverfix set up to track remote branch refs/remotes/origin/serverfix.
552-
Switched to a new branch "serverfix"
575+
Branch serverfix set up to track remote branch serverfix from origin.
576+
Switched to a new branch 'serverfix'
553577
----
554578

555579
This gives you a local branch that you can work on that starts where `origin/serverfix` is.
@@ -558,22 +582,22 @@ This gives you a local branch that you can work on that starts where `origin/ser
558582

559583
Checking out a local branch from a remote branch automatically creates what is called a _tracking branch_. Tracking branches are local branches that have a direct relationship to a remote branch. If you’re on a tracking branch and type `git push`, Git automatically knows which server and branch to push to. Also, running `git pull` while on one of these branches fetches all the remote references and then automatically merges in the corresponding remote branch.
560584

561-
When you clone a repository, it generally automatically creates a `master` branch that tracks `origin/master`. That’s why `git push` and `git pull` work out of the box with no other arguments. However, you can set up other tracking branches if you wish – ones that don’t track branches on `origin` and don’t track the `master` branch. The simple case is the example you just saw, running `git checkout -b [branch] [remotename]/[branch]`. If you have Git version 1.6.2 or later, you can also use the `--track` shorthand:
585+
When you clone a repository, it generally automatically creates a `master` branch that tracks `origin/master`. That’s why `git push` and `git pull` work out of the box with no other arguments. However, you can set up other tracking branches if you wish – ones that track branches on other remotes, or don’t track the `master` branch. The simple case is the example you just saw, running `git checkout -b [branch] [remotename]/[branch]`. If you have Git version 1.6.2 or later, you can also use the `--track` shorthand:
562586

563587
[source,shell]
564588
----
565589
$ git checkout --track origin/serverfix
566-
Branch serverfix set up to track remote branch refs/remotes/origin/serverfix.
567-
Switched to a new branch "serverfix"
590+
Branch serverfix set up to track remote branch serverfix from origin.
591+
Switched to a new branch 'serverfix'
568592
----
569593

570594
To set up a local branch with a different name than the remote branch, you can easily use the first version with a different local branch name:
571595

572596
[source,shell]
573597
----
574598
$ git checkout -b sf origin/serverfix
575-
Branch sf set up to track remote branch refs/remotes/origin/serverfix.
576-
Switched to a new branch "sf"
599+
Branch sf set up to track remote branch serverfix from origin.
600+
Switched to a new branch 'sf'
577601
----
578602

579603
Now, your local branch sf will automatically push to and pull from origin/serverfix.
@@ -586,7 +610,7 @@ Suppose you’re done with a remote branch – say, you and your collaborators a
586610
----
587611
$ git push origin :serverfix
588612
To [email protected]:schacon/simplegit.git
589-
- [deleted] serverfix
613+
- [deleted] serverfix
590614
----
591615

592616
Boom. No more branch on your server. You may want to dog-ear this page, because you’ll need that command, and you’ll likely forget the syntax. A way to remember this command is by recalling the `git push [remotename] [localbranch]:[remotebranch]` syntax that we went over a bit earlier. If you leave off the `[localbranch]` portion, then you’re basically saying, ``Take nothing on my side and make it be `[remotebranch]`.''

0 commit comments

Comments
 (0)