1.
SSH connection mode public key generation
Ssh-keygen-t rsa-c "[Email protected]"
Generate Id_rsa in the. SSH directory under the user's home directory, id_rsa.pub Add the Public key file (id_rsa.pub) content to the Sshkey in GitHub
2.
Configuration
git config--global user.email"[email protected]"git config--global User.Name"Your Name"get identity information git config--global--get User.emailwarning:LF 'll be replaced by CRLF|Fatal:crlf would is replaced by LF encounters these two errors because of the Git line break check feature. Core.safecrlfgit provides a line break check feature (CORE.SAFECRLF) that allows you to check if a file is mixed with different styles of line breaks at the time of submission, with the following options:false-Do not do any inspection warn-check and warn on committrue-check on commit and reject if found mixed if you're writing programs on Windows, or you're working with someone else, they're programming on windows, and you're on other systems, in these cases, You may encounter end-of-line terminator problems. This is because Windows uses a carriage return and a newline of two characters to end a line, while Mac and Linux use only a newline character. While this is a minor problem, it can greatly disrupt cross-platform collaboration. Git can automatically convert the line terminator CRLF to LF when you commit, and convert LF to CRLF when the code is checked out. Use CORE.AUTOCRLF to open this feature, if it is on a Windows system, set it to true so that when the code is checked out, LF will be converted to crlf:$ git config--global Core.autocrlftrueThe Linux or Mac system uses LF as the line terminator, so you don't want git to automatically convert when you check out a file, and when a file with CRLF as a line terminator is accidentally introduced, you'll want to fix it, set Core.autocrlf as input to tell Git Convert CRLF to LF on commit, do not convert when checked out: $ git config--Global CORE.AUTOCRLF input preserves CRLF in checked-out files on Windows systems, leaving LF on Mac and Linux systems, including warehouses. If you are a Windows programmer and you are developing a project that runs only on Windows, you can set false to cancel this function and record the carriage return in the library: $ git config--global Core.autocrlffalse
3.
Set Publishing mode
git config--global push.default simple/matchingmatching'matching'1 2. x default is simple, meaning that when executing git push does not specify a branch, only the current branch will be push to the code you get using git pull.
4.
Some common operations
git add filename git Add. Represents the current directory
git commit-m ' comment '-o filename
git push
Git checkout--<file> Discard workspace Changes (file changes in the working directory, not add undo changes) Replace the workspace version with the version in the repository
git reset HEAD <file> Withdraw Staging Area (add, but no commit file, offset already add operation)
git rm file (if the workspace or staging area has been modified, it will report err, a file in the repository, modified in the workspace (not add to staging area or add to staging area), direct git rm not allowed)
git commit-m ' delete file '-o file
Git rm is used to delete a file, if a file has been submitted to the repository, do not worry about accidental deletion, but be careful, you can only recover files to the latest version, you will lose the last commit after you modify the content
You can also delete this
RM file
git Add File
git commit-m ' delete file '-o file
Git reflog
View all history including fallback history
git log just looks at the version history from the beginning to the present (not including the fallback) $ git log--pretty=oneline
git reset--hard c5dd3a558005fb12f8 fallback to a version
5.
Branching operations
View Branches
Git branch-a (all branches include remote branches)
git checkout-b Dev
Create and switch to the dev branch
Equivalent
Git branch Dev
git checkout Dev
After the dev branch has been modified
Switch to Master Branch
git checkout Dev
Synchronize the branches on the line to local (no local branch)
For example, remote has branch B1 local no
git checkout-b origin/b1 Sync remote Branch to local
git merge dev merges dev to current branch
Note the--NO-FF parameter, which means that fast forward is disabled:
Git merge--no-ff-m "merge with No-ff" Dev
The merged history has branches, and can be seen to have been merged, and fast forward merger can not be seen to have been merged
To view the branch consolidation situation
git log--graph--pretty=oneline the full number submitted
Simple numbered display mode for operation
git log--graph--pretty=oneline--abbrev-commit
When a bug is temporarily modified, to ensure that the current workspace looks clean
To store the current unfinished work site.
Git stash
View a stored workspace
git stash List
[Email protected] {0}: WIP on b1:38b2a71 Modify p.php
Recovering a stored workspace
git stash apply [email protected]{0} (after recovery stash content is not deleted) need to use Git stash drop to delete
Git stash pop (restores the stored workspace and removes content from stash)
6. List the corresponding remote library
git remote-v
Origin https://github.com /hkui/test.git (Fetch)
Origin https://github.com/hkui/test.git (push)
7. Push local branch to remote
New branch locally such as (B1) push to remote ( New
git Push Origin B1 (local): B1 (remote)
After you set up a channel between local and remote branches, you do not have to write the 2-side branch names all at once
[email protected] MINGW32 ~/desktop/osc (B1)
$ git push
Fatal:the Current Branch B1 have no upstream branch.
to push the current branch and set the remote as upstream, use
git push--set-upstream Origin B1
To set the current local branch association with a remote branch
git push--set-upstream origin b1 (remote branch name exists or does not exist)
Delete Remote Branch
Git push Origin--delete B1 (remote branch)
Delete local branches (all published to remote repositories or merged into the main branch before they can be deleted)
Git branch-d branchname
Git branch-d branchname (no merged branch brute force Delete)
Label operations
git tag <tagname> [commit number] default to the currently committed commit
git tag View all tags
$ git log--pretty=oneline--abbrev-commit c097905 Add dev1.txt dev11.txt on branch dev1 a651ed5 Merge Branch'B2'0f7c6c7 Merge Branch'B1'99171bd Modify Ignore config file d379649 Add custom ignore file c568160 deleted B1.txt1862163Modify 9833ae7 Add a line on B2 branch 0e07e62 modify b1.txt 1a0cfa7 Modify B1 24549b6 modify files
9181725Modify Files f46e95b add a line on B2.txt 51ef312 add b2.txt on branch B1 55cedea add a line on B1.txt 38 fb557 add B1.txt on B1 branch 058c2f7 add a.php cec4d7c update readme.md cfbb500 update readme.md 04ec1f4 Ini Tial Commit
tag for a commit such as "Modify ignore config file" This commit tag
git tag p1.0 99171bd
Labels are not listed in chronological order, but are sorted alphabetically
Use git show <tagname> view tag information
$ git show P1.0Commit 99171bde2eddbf67b8860024504bc14556de2978 Author:hkui<764432054@qq .com>Date:fri Dec - the: A: the .+0800Modify Ignore configuration filediff--git A/.gitignore b/. Gitignore index e69de29.. Ef752b0100644---A/. Gitignore+ + + b. Gitignore @@-0,0+1 @@ +conf.php \ No newline at end offile
View Code
Create tagged tag
$ git tag-a <tangname> -M "Comment description" 3628164 (commit action number)
can also sign a label with the private key via-s
$ git tag-s tagname-m "signed version 0.2 released" fec145a
Delete label
$ git tag-d tagname
Push a tag to the remote
git Push Origin < Tagname>
pushes all tags that have not been pushed to the remote
$ git push Origin--tags
If the label has been pushed to the remote, to remove the remote label is a bit cumbersome, first remove the
$ git tag-d p1. 0 ' p1.0' (was 99171bd) then, removed from the remote. The Delete command is also push, but the format is as follows: git push origin:refs/tags/p1.0to https:// git.oschina.net/hk/code.git -[deleted] p1. 0
Git Common Command Summary