Github (III)

Source: Internet
Author: User

This time I will talk about several useful commands of git bash, including git log viewing and submission, git tag tagging and git diff checking and submitting changes.

Git log
git log [<options>] [<since>..<until>] [[--] <path>…]

By default, git log lists historical commit records of the current branch, including SHA-1 checksum, commit author, time, and comments.

 1 icefox@ICEFOX-PC /d/JavaScript/My Plugin/jquery-smartAt (master) 2 $ git log 3 commit 6c539aadc3125c04b38ab56e56cd454b5d5bfb8e 4 Author: icefox <icefox0801@hotmail.com> 5 Date:   Sun May 5 01:15:59 2013 +0800 6  7     add .gitattributes and .gitignore 8  9 commit 4aea315fe7b9ee43fce27fc1448ab02488a3bb7e10 Author: icefox <icefox0801@hotmail.com>11 Date:   Thu May 2 14:21:45 2013 +080012 13     bug fix14 :

If you press enter, one more row is displayed. Enter 'q' to exit.

Common Operations:

Git log-N: list the last n commit records

Git log -- oneline: Lists submission records in a single row. By default, only the abbreviated hash code and comments are submitted.

Git log-P: list detailed changes to the submission record

Git log-author = [authorname]: lists the submission records of an author.

Git log -- pretty [= <format>]: lists the submission records in the specified format. The <format> can beOneline,Short,Medium,Full,Fuller,Email,RawA string or a custom format. We can even specify a color for a placeholder, for example

1 $ git log --pretty="%h %Cgreen%s %Creset%ar"2 6c539aa add .gitattributes and .gitignore 21 hours ago3 4aea315 bug fix 3 days ago4 0adee72 Update README.md 4 days ago

% C-Reset is used to restore the default color. Here, there are many placeholders in <format>, which are not described in detail. Common abbreviated hash codes are % H-submitted, % an-submitted author, % ar-submitted relative date, % s-submitted comments, and so on.

Git log -- <path>: list the commits of a file or path. For example, git log -- index.htmlwill modify the commits of index.html.

Git log [<since> .. <until>]: lists the submission records between <since> and <until>. <since> and <until> can be abbreviated hash codes for submission or branch names.

Git tag
git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>]        <tagname> [<commit> | <object>]git tag -d <tagname>…git tag [-n[<num>]] -l [--contains <commit>] [--points-at <object>]        [--column[=<options>] | --no-column] [<pattern>…]        [<pattern>…]git tag -v <tagname>…

Git tag is used to add tags to the git repository. It is generally used to add version information. For example, you can add a "v0.1" tag to a git repository.

1 icefox@ICEFOX-PC /d/JavaScript/My Plugin/jquery-smartAt (master)2 $ git tag -a 'v0.1' -m 'v0.1'

After the v0.1 label is added, all the previous submissions will be under the v0.1 label, and all the commits after the v0.1 label time node will not be under v0.1, such

1 icefox@ICEFOX-PC /d/JavaScript/My Plugin/jquery-smartAt (master)2 $ vim test.html3 icefox@ICEFOX-PC /d/JavaScript/My Plugin/jquery-smartAt (master)4 $ git add test.html5 icefox@ICEFOX-PC /d/JavaScript/My Plugin/jquery-smartAt (master)6 $ git commit -a -m 'for git tag test'7 [master 423cae6] for git tag test8  1 file changed, 2 insertions(+)9  create mode 100644 test.html

We wrote a test.html file and submitted it. At this time, git log v0.1 found that there was no 'for git tag test' submitted this time. Then we added a v0.2 tag.

1 $ git tag -a 'v0.2' -m 'v0.2'

Git log v0.2 again, and found that the v0.2 tag contains 'for git tag test. Finally, to view the content submitted during the upgrade from v0.1 to v0.2

1 icefox@ICEFOX-PC /d/JavaScript/My Plugin/jquery-smartAt (master)2 $ git log v0.1..v0.2 --oneline3 423cae6 for git tag test

We can see that only the 'for git tag test' is submitted this time. In this way, you can add labels to the project on the important commit time node during git project development, so that you can add version information.

Common Operations:

Git tag-d <tagname>: delete tags from the local repository. To delete tags from a remote git repository, use git push origin: refs/tags/<tagname>

Git tag-l: list all the tags in the local repository

Git tag-a <tagname> <commit>: adds a tag to a previous commit, which is generally used for post-labeling.

Git diff
git diff [options] [<commit>] [--] [<path>…]git diff [options] --cached [<commit>] [--] [<path>…]git diff [options] <commit> <commit> [--] [<path>…]git diff [options] <blob> <blob>git diff [options] [--no-index] [--] <path> <path>

Git diff is used to view the difference between two commits or between one commit and the current working directory. By default, it is used to view the difference between the last commit and the current working directory.

 1 icefox@ICEFOX-PC /d/JavaScript/My Plugin/jquery-smartAt (master) 2 $ git diff 3 diff --git a/index.html b/index.html 4 index eb558a6..20dddfa 100644 5 --- a/index.html 6 +++ b/index.html 7 @@ -1,4 +1,4 @@ 8 -<!DOCTYPE html> 9 +new insert<!DOCTYPE html>10  

Common Operations:

Git diff <commit>: compare the difference between a certain commit and the current working directory. The HEAD indicates the last commit ~ 1 indicates the second to last, and so on.

Git diff <commit>: Compares the changes between two commits.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.