Git command line usage
Git command usage git installation package
Http://c35.yunpan.360.cn/my? Sid = # % 2F % E5 % AE % 89% E8 % A3 % 85% E5 % 8C % 85% 2 FGit % E5 % AE % 89% E8 % A3 % 85% 2F
How to generate the key during git Installation
1. git config -- global user. name xxx
2. git config -- global user. email xxx @ xxx
3. ssh-keygen-C xxx @ xxx-t rsa // step 3 is as follows:
(1) Press enter to select the default public key storage address
(2) private key password-leave it blank for later convenience
(3) generate the public key and private key identification has been saved in/c/Users/xxx /. ssh/id_rsa.public key has been saved in/c/Users/xxx /. ssh/id_rsa.pub. // git Public Key ------/c/Users/xxx /. ssh/id_rsa.pub. file Content
Ssh-rsa Secure/secure + EqaMoR9Yw + secure/PtK7tTI + eMKc/NZqhcp9e + NYIVzbwUMqvAnx + secure/secure + w63mhL + c8a8Qu + recommended SSH protocol xxx @ xxxgit The reason is that the SSH protocol can avoid entering the password for each push. The premise is to configure the SSH key in your account. The git@github.com begins with the SSH protocol. When you use Https, the user name and password will be entered each time.
Git bash command window and font size settings
Click the title bar of the git bash interface, right-click and select
// Window size settings
Options --> windows --> modify the number of rows (height) + number of columns (width)
// Window Font settings
Options --> text --> set the font size
// For other settings, refer to this article.
Http://my.oschina.net/lieefu/blog/476252
// Solve Chinese garbled characters of gitk in Windows
Http://howiefh.github.io/2014/10/11/git-encoding/
// Take a look at the Command window settings of win7
Http://article.pchome.net/content-1245289-all.html
Create local database
// Create 1.git init from scratch to create an empty Git library. Generate a. git subdirectory in the current directory. In the future, all file changes will be saved to this directory.
2. git init -- bare create a backup warehouse (a backup warehouse can be created in a path other than the server or project directory) // create a clone of an existing warehouse
Git clone/path/to/repository // local database
Git clone git/ssh/http [s]/ftp [s]/file/rsync: username @ ip/path/to/repository // Remote Server
The essence of git clone is to copy the content in the "Git directory". Generally, the "Git directory" contains thousands of objects (submit object, tree object, binary object, tag object ......), if you copy one by one, the efficiency can be imagined.
If it is transmitted through git or ssh, the server will pack the objects to be transmitted before transmission, whereas http (s) the Protocol repeatedly requests different objects to be transmitted. If there are not many commits in the repository, the efficiency of the former is similar to that of the latter. However, if there are many commits in the repository, the git and ssh protocols will be more efficient for transmission. But Now Git has optimized the Git repository for http (s) protocol transmission, and http (s) transmission can also achieve the efficiency of the ssh protocol.
COMMIT_EDITMSG # stores the comments of the last commit.
Config # project configuration information
Description # Project description
HEAD # index of the current branch of the Project # index file. The content to be added after git add is saved here.
Hooks/# default "hooks" Script File
Info/# There is an exclude file in it, which specifies the file to be ignored in this project #, take a look here
Logs/# historical information of each refs
Objects/# This directory is very important. It stores Git data objects.
# Includes: commit, trees, blobs, and tags ). # In the objects directory, the first two characters of the SHA string are used as the directory name, And the 38 characters are followed as the file name.
Refs/# identifies the commit (commit) to which each of your branches points ).
// View the content of the submitted file. 2d832d is the SHA (secure hash algorithm) signature value.
$ Git cat-file-p 2d832d
// For details, refer to the creation and composition of the local repository.
Http://www.infoq.com/cn/news/2011/02/git-adventures-local-repository
Workflow
Local and remote Workflow
Your local code is composed of three "Trees" maintained by git. The first is your working directory, which holds the actual file; the second is the cache area (Index/stage), which is like a cache area, temporarily saving your changes; finally, the local repository (HEAD) points to the result after your last submission.
Git clone is used to create a local repository. // origin is the default remote host name used by git clone.
After obtaining the remote git library through git clone, the developer information in. git/config will not be cloned together. You still need to add developer information to the. git/config file of the local database. In addition, developers also need to add their own. gitignore file. The remote git library obtained through git clone only contains the current working branch of the remote git library. If you want to obtain other branch information, you need to use "git branch-r" to view it. If you need to obtain other branch code remotely, you can run the command "git checkout-B local branch name remote branch name", where the remote branch name is the branch name listed by "git branch-r, it is generally like "origin/branch name. If the local branch name already exists, the "-B" parameter is not required.
Git fetch gets the latest version from a remote location and does not automatically merge, Which is safer than git pull. If you first use git fetch and then use git checkout nov/eclair_rocket, the latest update information is obtained from the server and the latest code is downloaded from the server. Git pull obtains code from the server repository and merges it with the local code. Equivalent to: the Git fetch + Git merge command gets the remote branch name of the remote git library to a local branch of the local git library. If the local branch name is not specified, the default pull is to the local branch. If your local branch already has content, git pull will merge these files. If there is a conflict, an alert will be reported. Git pull and git push are operations on all branches. That is to say, even if I switch to a sub-branch alpha, if this branch and the far branch are already associated, executing git pull will update both the master branch and alpha branch to the far end.
Git command line usage
Add and submit
You can plan changes (add them to the cache) by using the following command:
Git add dir1 # add the dir1 directory. All files in the directory are added.
Git add f1 f2 # add f1 and f2 files
Git add. # add all local (new and modified, not deleted) files to the temporary storage area
Git add-u # add local (modify and delete, not added) files to the temporary storage area
Git add-A/* # add all files in the current directory
# Git add-A = git add. + git add-u
Git add. # add all files and subdirectories in the current directory
Git rm -- cache a. c # delete files submitted to the local repository
This is the first step in git's basic workflow. Use the following command to submit the changes:
Git commit-m "code submission information"
Git commit-a-m "code commit information" # git commit-a converts an unstaged file into a staged file (this does not include a new (untracked) file), and then commit
Git commit -- amend # modify the committed commit (no push)
Git commit -- amend-m "comment" # modify the commit Annotation
Now, your changes have been submitted to the HEAD, but haven't arrived at your remote repository.
Push changes
Your changes are now in the HEAD of the local repository. Run the following command to submit the changes to the remote Repository:
Git push origin mastergit push does not automatically Merge files. Therefore, if a conflict occurs during git push, it will be forcibly overwritten by the content of the subsequent push file, and there is no prompt. This is very dangerous during cooperative development.
You can replace the master with any branch you want to push.
If you have not cloned an existing repository and want to connect your repository to a remote server, run the following command to add the Repository:
Git remote add origin
So that you can push your changes to the added server.
Branch
Branches are used to isolate feature development. When you create a repository, the master is "default ". Develop on other branches, and then merge them into the main branch.
Git checkout-B feature_x creates a branch named "feature_x" and switches over to it:
Switch back to main branch:
Git checkout master
Delete the new branch:
Git branch-d feature_x
Unless you push a branch to a remote repository, the Branch is invisible to others:
Git push origin
Rename local branch
Git branch-m branch-old-name branch-new-name
Update
To update your local repository to the latest changes, execute:
Git pull origin git fetch origin
Tag
It is recommended to create tags when the software is released. This is an old concept, and also exists in SVN. Run the following command to create a label named 1.0.0:
Git tag 1.0.0 1b2e1d63ff
1b2e1d63ff is the first 10 characters of the submission ID you want to mark. Run the following command to obtain the submission ID:
Git log
You can also use the first few digits of the submitted ID, as long as it is unique.
// Add comments to tags
Git tag-v1.4-m' my version 1.4'
// Display the tag version record git show tag-name // push all tags to the remote server git push origin -- tags
// Retrieve a version of git checkout-B branch_name tag_name that has been tagged
// Note when deleting a tag. If a tag is submitted to the remote server, you must delete the local tag and the remote tag.
// The command to delete a local tag is
Git tag-d tag-name
// The command to delete a remote tag is
Git push origin -- delete tag-name
Replace local changes
If you do something wrong (naturally, this is not possible), you can use the following command to replace the local change:
Git checkout --
This command replaces the files in your working directory with the latest content in the HEAD. Changes that have been added to the cache and new files are not affected.
If you want to discard all your local changes and commits, you can get the latest version on the server and direct your local branches to it:
Git fetch origin master
Git reset origin/master -- hard
How git ignores File Settings
Refer to the following two URLs:
Three methods for setting git ignore files [http://www.jianshu.com/p/267cd94f1d49]
Git ignore file setting syntax [http://www.cnblogs.com/pylemon/archive/2012/07/16/2593112.html#3226325]
The point is:
You can ignore the. gitignore file. The ignored files are only valid for files not tracked and invalid for files already added to the version library.