-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
2. $ git status can tell us merge conflict is inside index.html
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)
the .gitignore file is used to tell Git about the files that Git should not track. This file should be placed in the same directory that the .git directory is in.
Step1: Add file .gitignore, in the same directory as .git
1
$ touch .gitignore
Step2: write the ignored file name in the .gitignore
1
$ open .gitignore
Add the following line in it.
1 2 3 4
project.docx
samples/*.jpg # All the .jpg files in 'samples' directory
commit 5de135ab4ca51b7d86b53ea1f81bca100c6eeb40 Author: Richard Kalehoff <richardkalehoff@gmail.com> Date: Sat Dec 3 15:42:07 2016 -0500
Set article timestamp color
Display commits in oneline
1
$ git log --oneline
This command:
lists one commit per line
shows the first 7 characters of the commit’s SHA
shows the commit’s message
OUTPUT
1 2 3 4 5
6f04ddd Add breakpoint for large-sized screens 50d835d Add breakpoint for medium-sized screens 0768f3d Add space around page edge f9720a9 Style page header ...
git log --stat Recap
--stat is a flag
To recap, the --stat flag is used to alter how git log displays information:
1
$ git log --stat
1
$ git log 8d3ea36 --stat
This command:
displays the file(s) that have been modified
displays the number of lines that have been added/removed
displays a summary line with the total number of modified files and lines that have been added/removed
git log -p Recap
To recap, the -p flag (which is the same as the --patch flag) is used to alter how git log displays information:
1
$ git log -p
This command adds the following to the default output:
displays the files that have been modified
displays the location of the lines that have been added/removed
displays the actual changes that have been made
1
$ git log -p -w
With-w, don’t highlight lines where only whitespace changes occurred.
Annotated git log -p Output
git log -p or git log --patch
Using the image above, let’s do a quick recap of the git log -p output:
🔵 - the file that is being displayed
🔶 - the hash of the first version of the file and the hash of the second version of the file not usually important, so it’s safe to ignore
❤️ - the old version and current version of the file
🔍 - the lines where the file is added and how many lines there are
-15,83 indicates that the old version (represented by the -) started at line 15 and that the file had 83 lines
+15,85 indicates that the current version (represented by the +) starts at line 15 and that there are now 85 lines…these 85 lines are shown in the patch below
✏️ - the actual changes made in the commit
lines that are red and start with a minus (-) were in the original version of the file but have been removed by the commit
lines that are green and start with a plus (+) are new lines that have been added in the commit
git show
git show can be combined with most of the other flags we’ve looked at:
--stat - to show the how many files were changed and the number of lines that were added/removed
-p or --patch - this the default, but if --stat is used, the patch won’t display, so pass -p to add it again