Common git commands

Source: Internet
Author: User
Tags git commands

Git knowledge points at a glance

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/4A/4D/wKiom1QkJLryc8cQABgd2dZu-Pk563.jpg "Title =" 11.png" alt = "wKiom1QkJLryc8cQABgd2dZu-Pk563.jpg"/>

Git is mainly divided into three areas: the workspace (working directory) temporary storage area (staging area) version Library (History)

Workspace: folder currently working

Temporary Storage Area: You can submit the changes in the workspace to the cache area and save them. It is equivalent to the cache of the submitted task.

Add. Git/Index

Version Library: server files

Commit. Git/objects


Git advantages

Suitable for distributed development with emphasis on individuals. The pressure on public servers and the amount of data will not be too large. Fast and flexible. Any two developers can easily resolve conflicts.


[Installation and initialization]

1. Configure the global user name and email address

[[Email protected] ~] # Git config -- global user. Name 'zhengyansheng' # Set the user name [email protected] ~] # Git config -- global user. Email '[email protected]' # Set the user Email Address [[email protected] ~] # Git config -- Global color. UI true # Set the color of the Print Output font [[email protected] ~] # Git config -- list # list all configurations of the current user. User. Name = zhengyansheng [email protected] color. UI = true [[email protected] ~] # Cat/root /. gitconfig [user] Name = zhengyanshengemail = [email protected] [color] UI = true Note: # user name and email usage: the identifier of the Code submitted by the developer # git config -- Global is equivalent to modifying the hidden file. gitconfig


2. initialize the version Library

# Create a library folder [[email protected] ~] # Mkdir-P/root/to/repo [[email protected] ~] # Cd/root/to/repo/# initialize the raw repository [[email protected] repo] # git initinitialized empty git repository in/root/to/repo /. git/# Put all the files in the workspace in the temporary storage area [[email protected] repo] # git add. # [email protected] repo] # git commit-m'initial import'


Clone local database

[[email protected] repo]# cd ..[[email protected] to]# mkdir project[[email protected] to]# cd project/[[email protected] project]# git clone https://github.com/gitlabhq/gitlabhq.git
[[Email protected] project] # ll total usage 4drwxr-xr-x 15 Root 4096 September 26 07:06 gitlabhq [[[email protected] project] # ll gitlabhq/total usage 172drwxr-xr-x 12 Root 4096 September 26 07:06 appdrwxr -XR-x 2 root Root 4096 September 26 07:06 bin-RW-r -- 1 Root 34581 September 26 07:06 changelogdrwxr-XR-x 5 root Root 4096 September 26 07:06 config-RW-R -- r -- 1 Root 429 September 26 07:06 config.ru-RW-r -- 1 Root 11550 September 26 07:06 contributing. mddrwxr-XR-x 4 Root 4096 September 26 07:06 dbdrwxr-XR-x 19 Root 4096 September 26 07:06 docdrwxr-XR-x 10 Root 4096 September 26 07:06 features-RW-r -- r -- 1 Root 4710 September 26 07:06 gemfile-RW-r -- 1 Root 16349 September 26 07:06 gemfile. lock-RW-r -- 1 Root 6 September 26 07:06 GITLAB_SHELL_VERSION-rw-r -- r -- 1 Root 1278 September 26 07:06 guardfiledrwxr-XR-x 9 Root 4096 September 26 07:06 Lib-RW-R -- r -- 1 Root 1060 September 26 07:06 licensedrwxr-XR-x 2 root Root 4096 September 26 07:06 log-RW-r -- 1 Root 1359 September 26 07:06 maintenance. MD-RW-r -- 1 Root 9507 September 26 07:06 process. MD-RW-r -- 1 Root 231 September 26 07:06 procfiledrwxr-XR-x 3 Root 4096 September 26 07:06 public-RW-r -- 1 Root 271 September 26 07:06 rakefile -RW-r -- 1 Root 6049 September 26 07:06 readme. mddrwxr-XR-x 18 Root 4096 September 26 07:06 specdrwxr-XR-x 4 Root 4096 September 26 07:06 tmpdrwxr-XR-x 4 Root 4096 September 26 07:06 vendor-RW-r -- r -- 1 Root 10 07:06 version


[Submit Code]

Submit the changes in the directory to git.

[[email protected] gitlabhq]# echo "I Love You" > aa[[email protected] gitlabhq]# git add aa[[email protected] gitlabhq]# git commit -m ‘add aa‘[master 92647aa] add aa 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 aa [[email protected] gitlabhq]# git logcommit 92647aaa53a5254dbb207e54906a750576c75cfdAuthor: zhengyansheng <[email protected]>Date:   Fri Sep 26 07:47:59 2014 +0800    add aa


Push to remote database

[[email protected] gitlabhq]# git push

Then, view the AA file we pushed on the GIT server.


Temporary File modifications that have been included in git Version Control

Git add AA

Submit all modifications to files under git Version Control

Git commit-M "add file AA"

Clear changes in the working directory tree

Git checkout head AA

Cancel the temporary ID that has been saved but has not been submitted

Git reset head AA


[History]

Show all history records

Git log

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4A/55/wKiom1QkPn_yFwLMAAL7OU72BuU746.jpg "Title =" 21.png" alt = "wkiom1qkpn_yfwlmaal7ou72buu746.jpg"/>

Display version history and content differences between versions

Git log-P

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4A/55/wKiom1QkPtiziDScAAMBpO6I7xw153.jpg "Title =" 22.png" alt = "wkiom1qkptizidscaambpo6i7xw153.jpg"/>

Show only the last submission

Git log-1

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/4A/57/wKioL1QkP3jiBfkxAADULLjQ2u4702.jpg "style =" float: none; "Title =" 23.png" alt = "wkiol1qkp3jibfkxaadulljq2u4702.jpg"/>


Displays the last 20 submissions and content differences between versions.

Git log-1-P

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4A/57/wKioL1QkP3jQvn5YAAFedFvBMtY059.jpg "style =" float: none; "Title =" 24.png" alt = "wkiol1qkp3jqvn5yaafedfvbmty059.jpg"/>



Show submissions in the last 6 hours

Git log-since = "6 hours"

 

Displays the submissions two days ago.

Git log-before = "2 days"

 

Displays the three commits earlier than the head (the ending point of the current branch ).

Git log-1 Head ~ 3

Or

Git log-1 Head ^

Or

Git log-1 Head ~ 1 ^



[Advanced functions]

Git revert:

To restore a version modification, you must provide a specific git version number, for example, 'git revert bbaf6fb5060b4875b18ff9ff637ce118256d6f20 '. The GIT version number is a generated hash value.



Git checkout:

Git checkout has two functions. One is to switch between different branchs. For example, 'git checkout new_branch 'switches to the new_branch branch. The other function is to restore the code, for example, 'git checkout APP/model/user. RB, the user. the RB file is updated from the previous submitted version. All unsubmitted content will be rolled back.



Git Reset:

Roll back the current working directory to the specified version. Suppose, for example, we have the version submitted five times by the A-G, where the C version number is bbaf6fb5060b4875b18ff9ff637ce118256d6f20, we executed the 'git reset bbaf6fb5060b4875b18ff9ff637ce118256d6f20 ', then the result is only three submitted versions of the A-C.



Differences between git revert and git Reset

Git revert is used to cancel an operation. The commit before this operation will be retained.

Git reset revokes a certain commit, but all subsequent modifications will be returned to the temporary store.




Learning Source:

Http://rfyiamcool.blog.51cto.com/1030776/1150287

This article from "Zheng Yansheng" blog, please be sure to keep this source http://467754239.blog.51cto.com/4878013/1558287

Common git commands

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.