Git commands and Common commands
As a common version control tool, Git can save a lot of time, the following picture is a better one, posted a look:
For git, first you need to know a few nouns, as follows:
Workspace //workspace index/stage// registers
Repository //Warehouse area (or local warehouse)
remote/long distance Warehouse
One, new code base
Create a new Git code base in the current directory
$ git init
//Create a new directory, initialize it to git code base
$ git init [project-name]
//Download a project and its entire code history c15/>$ git clone [url]
Second, the configuration
Git's settings file is. gitconfig, which can be in the user's home directory (global configuration) or under the project directory (project configuration).
Show current git configuration
$ git config--list
//Edit git configuration file
$ git config-e [--global]
//Set user information when submitting code
$ git C Onfig [--global] User.Name "[name]"
$ git config [--global] user.email "[Email address]"
Iii. Add/Remove Files
Add the specified file to registers
$ git add [file1] [file2] ...
Add the specified directory to registers, including subdirectories
$ git add [dir]
///Add all files in current directory to registers
$ git Add.
Before adding each change, you will be asked to confirm
//For multiple changes to the same file, you can implement the sub-submit
$ git add-p
//delete workspace file, and put this deletion into registers
$ git rm [file1] [file2 ]
//Stop tracing the specified file, but the file will remain in the workspace
$ git rm--cached [file]
//rename files and put this name in registers
$ git mv [file-original] [ File-renamed]
Iv. Code Submission
Submit registers to warehouse area
$ git commit-m [message]
//Submit registers designated file to warehouse
$ git commit [file1] [file2] ...-m [message]
//Submit workspace Changes after last commit, direct to warehouse area
$ git commit-a
//Submit all diff
$ git commit-v
//Use a new commit, Replace the last commit
//If the code does not have any new changes, use to overwrite the commit information of the last commit
$ git commit--amend-m [message]
//Redo the last commit, and includes new changes to the specified file
$ git commit--amend [file1] [file2]
V, Branch
List all local branches
$ git branch
//List all remote branches
$ git branch-r
//List all local branch and remote branch
$ git branch-a
//New branch, but depending on Then stay in the current branch
$ git branch [branch-name]
//Create a new branch and switch to the branch
$ git checkout-b [branch]
//New branch, point to specified commit< c11/>$ git Branch [branch] [commit]
//Create a new branch to establish a tracking relationship with the specified remote branch
$ git Branch--track [branch] [Remote-branch]
//switch to the specified branch and update the workspace
$ git checkout [branch-name]
//Switch to the previous branch
$ git checkout-//
set up a tracking relationship, Between an existing branch and a specified remote branch
$ git Branch--set-upstream [branch] [Remote-branch]
//merge the specified branch to the current branch
$ git merge [branch]
//Select a commit to merge into the current branch
$ git cherry-pick [commit]
//Delete branch
$ git branch-d [branch-name]
// Delete Remote Branch
$ GIT push Origin--delete [Branch-name]
$ git branch-dr [remote/branch]
Six, label
List all tag
$ git tag
//Create a tag in the current commit
$ git tag [tag]
//Create a tag in the specified commit
$ git tag [commit]< c6/>//Delete local tag
$ git tag-d [tag]
//Remove remote tag
$ git push origin:refs/tags/[tagname]
//view tag info
$ git Show [tag]
//Submit specified tag
$ git push [remote] [tag]
//Submit all tag
$ git push [remote]--tags
//New branch, Point to a tag
$ git checkout-b [branch] [tag]
Vii. View information
/Show changed file $ git status//Display current branch version history $ git log//show commit history, and every commit to change the file $ gi T log--stat//Search submission history, according to the keyword $ git log-s [keyword]//show all changes after a commit, each commit occupies one line of $ git log [tag] head--pretty=form at:%s//Displays all changes after a commit, and its "submission instructions" must match the search terms $ git log [tag] head--grep feature//display a version history of a file, including file Rename $ git log--follow [File] $ git whatchanged [file]//show specified file related per diff $ git log-p [file]//Show last 5 submissions $ git log-5--pretty--oneline// Show all submitted users, sorted by number of submissions $ git SHORTLOG-SN//show specified file what time has the person modified $ git blame [file]//show registers and Workspace differences $ git diff//show registers and prev C Ommit difference $ git diff--cached [file]//Show differences between the workspace and current branch latest commit $ git diff head//show two times the difference between commits $ git diff [First-branch]. .. [Second-branch]//show how many lines of code you wrote today $ git diff--shortstat "@{0 Day ago}"//display changes in metadata and content for a submission $ git show [commit]//display a Commit
The changed file $ git show--name-only [commit]//shows the contents of a file at a time of submission $ git show [commit]:[filename]//Display the current branch's last few submissions $ git reflog
Eight, remote synchronization
# Download all changes to the remote warehouse
$ git fetch [remote]
# Show All remote warehouses
$ git remote-v
# Display information for a remote warehouse $ git remote show
[remote]
# Add a new remote warehouse, and name
$ git remote add [shortname] [url] # Take back
the changes from the warehouse and merge with the local branch
$ git pull [remote] [branch]
# upload Local designated branch to remote warehouse
$ git push [remote] [branch]
# forcibly push current branch to remote warehouse, even if there is conflict
$ git push [remote]--force
# Push all branches to remote warehouse
$ git push [remote]--all
Ix. Revocation of
Restore registers to workspace
$ git checkout [file]
//Restore a commit's specified file to registers and workspace
$ git checkout [commit] [file]
// Recover all files from registers to workspace
$ git checkout.
Resets the specified file for registers, consistent with the previous commit, but the workspace does not change
$ git reset [file]
//Reset registers and workspace, consistent with previous commit
$ git reset--hard
//Reset the current branch pointer to the specified commit, while resetting the registers, but the workspace does not change
$ git reset [commit]//Reset the head
of the current branch to the specified commit, resetting the registers and the workspace, With the specified commit
$ git reset--hard [commit]
//Reset the current head for the specified commit, but keep the registers and the workspace unchanged
$ git reset--keep [commit]< c16/>//creates a new commit that cancels
all changes to the specified commit//latter and is applied to the current branch
$ git revert [commit]
//Temporarily remove uncommitted changes, Move again later
$ git stash
$ git stash pop
Ten, other
Generate a Zip package available for release
$ git archive
Thank you for reading, I hope to help you, thank you for your support for this site!