First, create a new code base
# Create a new Git codebase in the current directory
$ git init
# Create a new directory and initialize it to git code base
$ git init [project-name]
# Download a project and its entire code history
$ git clone [url]
Second, the configuration
The settings file for Git is. Gitconfig, which can be in the user's home directory (global configuration) or under the project directory (project configuration).
# show current git config
$ git config--list
# edit git config file
$ git config-e [--global]
# Set the user information when submitting code
$ git conf IG [--global] User.Name "[name]"
$ git config [--global] user.email "[Email address]"
third, add/delete files
# Add the specified file to staging area
[file1[file2. . .
# Add the specified directory to staging area, including subdirectories
$ git add [dir]
# to add all files of the current directory to staging area
.
# before adding each change, will ask to confirm
# for multiple changes to the same file, you can implement the sub-commit
$ git add-p
# to delete the workspace file and put this deletion into staging area
$ git rm [file1] [file2 ] ...
# Stop tracking the specified file, but the file will remain in the workspace
$ git rm--cached [file]
# Renaming files and put this renaming into staging area
$ git mv [file-original] [ File-renamed]
Iv. Code Submission
# Submit staging Area to warehouse area
[message]
# Submit Staging area specified file to warehouse area
[file1 [file2. . [message] # commit workspace changes since last commit, direct to warehouse area $
git commit-a
# Show all diff information on commit
$ git commit-v
# Use a new commit, instead of the last commit
# If the code does not have any new changes, it is used to overwrite the commit information of the last commit
$ git Commit--amend-m [message]
# redo the last commit and include a new change to the specified file
$ git commit--amend [file1] [file2] ...
v. Branches
# List all local branches$ git Branch# list all remote branches $ git branch-r # list all local and remote branches$ git Branch -A# Create a new branch, but still stay in the current branch$ git Branch[Branch-name]# Create a new branch and switch to that branch$ git checkout- b[Branch]# Create a new branch, point to specify commit $ git branch [branch] [commit] # Create a new branch, 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-# Establish a tracking relationship between the existing branch and the specified remote branch $ git branch--set-upstream [branch] [remote-branch] # Merge the specified branch into the current branch $ git merge [branch] # Select a C Ommit, merge into 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 new tag in the current commit
$ git tag [tag]
# Create a new tag in the specified commit
$ git tag [tag] [commit]
# Delete local tag
$ git tag-d [tag]
# Delete remote tag
$ git push origin:refs/tags/[tagname]
# view Tag info
$ git sho w [tag]
# Commit specify tag
$ git push [remote] [tag]
# Commit all tag
$ git push [remote]--tags
# Create a new branch, point to a tag
$ git checkout-b [branch] [tag]
Vii. Viewing information
# shows the changedfile $ git status# shows the version history of the current branch$ git log# Show Commit history, and every commit changed file $ git log--stat # Search commit history, according to keyword $ git log-s [keyword] # show all changes after a commit, each commit occupies a line of $ git log [tag] head--pretty=format:%s # shows all the changes after a commit, whose "commit description" must match the search criteria $ git log [tag] head--grep feature # shows a file's Version history, including file Rename $ git log--follow [file] $ git whatchanged [file] # Displays the specified file related every time the diff $ git log-p [file] # shows the last 5 commits $ git l Og-5--pretty--oneline # Show all submitted users, sort by commits $ git shortlog-sn # shows what time the specified file was modified by git blame [file] # Show staging area and workspaceCodeDifference$ git diff# shows the difference between staging area and the previous commit $ git diff--cached [file] # shows the difference between the workspace and the current branch of the latest commit $ git diff HEAD # show two commits difference $ git diff [firs T-branch] ... [Second-branch] # shows how many lines of code you wrote today $ git diff--shortstat "@{0 Day Ago}" # Show metadata and content changes for a commit$ git show[Commit]# shows a file that has changed in a commit $ git show--name-only [commit] # Displays the contents of a file when a commit, git show [Commit]:[filename] # shows the most recent commit of the current branch $ git r Eflog # Update the current branch from the local master pull replacement code: branch is generally master$ git rebase [branch]
Eight, remote synchronization
# Download all changes to the remote repository
$ git fetch [remote]
# Show All remote warehouses
$ git remote-v
# Show information for a remote repository
$ git remote show [remote]
# Add a new remote repository and name git remote
add [shortname] [url]
# Retrieve the changes from the remote repository and merge
with the local branch [remote [branch ]# upload locally designated branch to remote repository [remotes]
[branch]
# forcibly pushes the current branch to the remote repository, even if there is a conflict
$ git push [remote]--force
# pushes all branches to the remote repository
$ git push [remote]--all
ix. Revocation
# Restore Staging area specified file to workspace
$ git checkout [file]
# Restore specified file of a commit to staging area and workspace
$ git checkout [commit] [file]
# Recover all files from staging area to workspace
$ git checkout.
# Reset Staging Area specified file, consistent with last commit, but workspace unchanged
$ git reset [file]
# Reset Staging area and workspace, consistent
with last commit --hard
# Resets the current branch pointer to the specified commit while resetting the staging area, but the workspace is unchanged
$ git reset [commit]
# resets the current branch's head to the specified commit, while resetting the staging area and workspace, Consistent with the specified commit
$ git reset--hard [commit]
# resets the current head to the specified commit, but keeps staging area and workspace unchanged
$ git reset--keep [commit]
# Create a new commit to undo the specified commit
# All changes to the latter will be offset by the former and applied to the current branch
$ git revert [commit]
# temporarily remove uncommitted changes and move back in later
$ git stash
$ git stash pop
10. Other
# Generate a Zip package available for release
$ git archive