Tagging,Branching, and Merging

Git Tagging

List all tags

1
$ git tag

Tag commits

1
$ git tag -a v1.0
  1. add a tag to the most recent commits

  2. -a means annotated, include extra information for the tag

    You can also $ git tag v1.0, but -a is recommended

Tag a specific commit

1
$ git tag -a v1.0 a87984

See all commits with the tag

1
$ git log v1.0

Delete a tag

1
$ git tag -d v1.0

Git Branch

1. List all branches

1
$ git branch

You can also find which branch you are currently in through it.

2. Create a branch

1
$ git branch sidebar
  • newly created branch sidebar points to the same commit as master

2.1 Create a brach points to a specific commit

1
$ git branch sidebar 42a69f

3. Switch branch

1
$ git checkout sidebar
  • remove all files and directories from the Working Directory that Git is tracking

    • (files that Git tracks are stored in the repository, so nothing is lost)
  • go into the repository and pull out all of the files and directories of the commit that the branch points to

4. See all commits in the branch

  • Fistly, checkout to this branch, then:
1
$ git log

HEAD--> points to the active branch

5. Delete a brach

1
$ git branch -d sidebar

6. Switch and Create Branch In One Command

1
$ git checkout -b sidebar

7. See All Branches At Once

1
$ git log --oneline --graph --all

Git Merging

1
$ git merge <name-of-branch-to-merge-in>

In the branch A, git merge B, then merge branch B to A

  • Fast-forward Merge

the branch being merged in must be ahead of the checked out branch. The checked out branch’s pointer will just be moved forward to point to the same commit as the other branch.

  • the regular type of merge
    • two divergent branches are combined
    • a merge commit is created

Merge Conflitcs

1. $ git merge heading-update

image-20180615164340641

2. $ git status can tell us merge conflict is inside index.html

image-20180615163421278

3. open index.html

Merge Conflict Indicators Explanation

The editor has the following merge conflict indicators:

  • <<<<<<< HEAD everything below this line (until the next indicator) shows you what’s on the current branch
  • ||||||| merged common ancestors everything below this line (until the next indicator) shows you what the original lines were
  • ======= is the end of the original lines, everything that follows (until the next indicator) is what’s on the branch that’s being merged in
  • >>>>>>> heading-update is the ending indicator of what’s on the branch that’s being merged in (in this case, the heading-update branch)

3. save the file, stage and commit it.