Read the snow-capped teacher git tutorial today to do some summary
Git Use commands
Initializing the Warehouse
Git init
Set User name password
git config--global user.name "Your name"
git config--global user.email "[Email protected]"
Add files to a git repository to add multiple files repeatedly
git add <file>
Submit File
Git commit-m "Remarks"
Show Change status in color
git config [--global] color.ui True
View Workspace Status
git status
See which content has been modified
Git diff
View submission history parameters [Pretty=oneline] simplified display information
git log [pretty=oneline]
Back to which version of the HEAD refers to the current version; head^ refers to the previous version; head^^ version head~100 100 versions ...
git reset--hard commit_id
Back to the future version and view the command history to confirm the future version number commit_id
Git reflog
When the workspace modification is discarded
Git checkout--<file>
Submitted to staging area stages want to discard modifications
git reset HEAD <file>
Git checkout--<file>
Delete a file from a repository
git rm <file>
Restore from repository to workspace version "one-click Restore"
Git checkout--<file>
Create SSH Key
$ ssh-keygen-t rsa-c "[Email protected]"
Associate a remote warehouse Xx.git remote Warehouse Address
Git remote add Origin xx.git
The first time you push all the contents of the master branch
Git push-u Origin Master
To clone a warehouse, you must first know the address of the warehouse and then clone it using the git clone command. GIT supports multiple protocols, including HTTPS, but the native GIT protocol supported by SSH is the fastest.
git clone xx.git
View Branches
Git branch
Create a branch
Git branch <name>
Switch branches
git checkout <name>
Create + Toggle Branch
Git checkout-b <name>
Merge a branch to the current branch
git merge <name>
Delete Branch
Git branch-d <name>
View Branch Merge Diagram
git log--graph
By forcing the fast forward mode to be disabled, Git generates a new commit at merge, so that branching information can be seen from the branch history.
Git merge--no-ff-m "remarks" dev/* Branch */
When the work is not finished, first put the work site Git stash, and then to fix the bug, repair, then git stash pop, back to the job site.
Git stash//store up your work and finish another job
git stash pop//back to Work * * shortcut key = = Git stash apply stash_id + git stash drop stash_id*/
View Stash List
git stash List
Force Delete a branch <name> Note: The current position cannot be on the deleted branch
Git branch-d <name>
viewing Remote Library information
Git remote-v
Crawling Remote Updates
Git pull Origin Branch-name
Local Push Branch
Git push Origin Branch-name
Local and remote branches are the best to create local and remote branch branches
git checkout-b branch-name origin/branch-name
Establish associations for local and remote branches
Git branch--set-upstream branch-name origin/branch-name
Create a new label default to head
git tag <name> [commit_id]
View all Tags
git tag
View label Information
Git show <tagname>
Create label with description---label name-m Specify descriptive text
Git tag-a version number (v1.0)-M "Remarks" commit_id
You can sign a private key with the private key through-s to install GPG encryption tool and generate GPG private key
Git tag-s version number-M "Remarks" commit_id
Push a local label
Git push Origin <tagname>
Push all local labels that have been pushed
Git push Origin--tags
Delete a local label
Git tag-d <tagname>
Delete a remote label
git push origin:refs/tags/<tagname>
Ignore the submitted file
! Create the. gitignore file under the root directory of the. git peer, vim. Gitignore edit the files you want to ignore. such as *.db,desktop.ini, etc.
Configure aliases
git config [--global] alias. Shorthand commands < such as st> command/"" < such as status/"Reset HEAD" >
Build a git server
1, must be in roo identity
Yum Install git
AddUser git
passwd git
2, switch user git, create warehouse
Su git
Select a directory as the Git repository, assuming/srv/sample.git, enter the command in the/SRV directory
$ sudo git init--bare sample.git
$ sudo chown-r git:git sample.git
3. Create a certificate login to collect the public key of the project group owner
SCP Project group local public key path/id_rsa.pub [email protected] (warehouse path)
4, write everyone's public key into the/home/git/.ssh/authorized_keys file, one line at a
Cat id_rsa.pub<1> id_rsa.pub<2>. >>. ssh/authorized_keys file, one line
5, prohibit Shell login
Permissions User root
vim/etc/passwd
Put git:x:1001:1001:,,,:/home/git:/bin/bash
Switch
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
6, Clone remote warehouse SERVER-->192.168.0.188<IP address >
$ git clone [email protected]:/srv/sample.git
Easy to manage public key, with Gitosis
When you configure Git, add--global to the current user, without working on the current warehouse
git configuration files for each repository are placed in the. git/config file
Alias is immediately after [alias], to delete the alias, the corresponding line can be deleted directly
The current user's git configuration file is placed in a hidden file in the user's home directory. Gitconfig
Git Use Command Summary