Here are three commands from the Internet
[commit] denotes the corresponding version number
Generally speaking, just remember the command 6 below for daily use. But skilled use, I'm afraid to remember 60 to 100 commands.
Here are some of the common things I've sorted out. Git List of commands. The translations of several special nouns are as follows.
- Workspace: Workspace
- Index / Stage: Temporary Zone
- Repository: Warehouse area (or local warehouse)
- Remote: Remote Warehouse
New Code Base
# Create a new Git code base in the current directory
$ git init
# Create a new directory and initialize it as a Git code base
$ git init [project-name]
# Download a project and its entire code history
$ git clone [url]
Two, configuration
Git's settings file is. gitconfig, which can be either in the user's home directory (global configuration) or in the project directory (project configuration).
# Display the current Git configuration
$ git config --list
# Edit Git configuration file
$ git config -e [--global]
# Setting user information when submitting code
$ git config [--global] user.name "[name]"
$ git config [--global] user.email "[email address]"
Increase/delete files
# Add the specified file to the temporary area
$ git add [file1] [file2] ...
# Add the specified directory to the temporary area, including subdirectories
$ git add [dir]
# Add all files of the current directory to the temporary area
$ git add .
# Validation is required before adding each change
# For multiple changes in the same file, it is possible to submit in stages
$ git add -p
# Delete the workspace file and place this deletion in the temporary area
$ git rm [file1] [file2] ...
# Stop tracking the specified file, but it will remain in the workspace
$ git rm --cached [file]
# Rename the file and put the rename in the temporary storage area
$ git mv [file-original] [file-renamed]
Code submission
# Submit temporary storage area to warehouse area
$ git commit -m [message]
# Submit designated documents from temporary storage area to warehouse area
$ git commit [file1] [file2] ... -m [message]
# Submit workspace changes since the last commit, directly to the warehouse
$ git commit -a
# Display all diff information on submission
$ git commit -v
# Use a new commit instead of the last commit
# If there is no new change in the code, it is used to rewrite the commit submission information of the previous commit
$ git commit --amend -m [message]
# Redo the last commit and include new changes to the specified file
$ git commit --amend [file1] [file2] ...
Five, branch
# List all local branches
$ git branch
# List all remote branches
$ git branch -r
# List all local and remote branches
$ git branch -a
# Build a new branch, but still stay in the current branch
$ git branch [branch-name]
# Create a new branch and switch to it
$ git checkout -b [branch]
# Create a new branch to point to the specified commit
$ git branch [branch] [commit]
# Create a new branch to establish a trace 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 trace 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 and merge it into the current branch
$ git cherry-pick [commit]
# Delete branch
$ git branch -d [branch-name]
# Delete remote branches
$ git push origin --delete [branch-name]
$ git branch -dr [remote/branch]
Six, label
# List all tag s
$ git tag
# Create a new tag in the current commit
$ git tag [tag]
# Create a new tag to specify commit
$ git tag [tag] [commit]
# Delete local Tags
$ git tag -d [tag]
# Delete remote Tags
$ git push origin :refs/tags/[tagName]
# View tag information
$ git show [tag]
# Submit the specified tag
$ git push [remote] [tag]
# Submit all tag s
$ git push [remote] --tags
# Create a new branch to point to a tag
$ git checkout -b [branch] [tag]
7. Viewing Information
# Display changed files
$ git status
# Display the version history of the current branch
$ git log
# Display the history of commit and the files that change each commit
$ git log --stat
# Search submission history, based on keywords
$ git log -S [keyword]
# Displays all changes after a commit, with each commit occupying one line
$ git log [tag] HEAD --pretty=format:%s
# Display all changes after a commit whose "submit notes" must meet the search criteria
$ git log [tag] HEAD --grep feature
# Display the version history of a file, including file renaming
$ git log --follow [file]
$ git whatchanged [file]
# Display each diff associated with the specified file
$ git log -p [file]
# Display the past five submissions
$ git log -5 --pretty --oneline
# Display all submitted users, sorted by number of submissions
$ git shortlog -sn
# Displays who and when the specified file was modified
$ git blame [file]
# Display differences between temporary and workspace
$ git diff
# Show the difference between the temporary area and the previous commit
$ git diff --cached [file]
# Show the difference between the workspace and the latest commit of the current branch
$ git diff HEAD
# Show the difference between two submissions
$ git diff [first-branch]...[second-branch]
# Show how many lines of code you wrote today
$ git diff --shortstat "@{0 day ago}"
# Display metadata and content changes for a submission
$ git show [commit]
# Display a document that has changed in a submission
$ git show --name-only [commit]
# Display the contents of a file on a submission
$ git show [commit]:[filename]
# Show the latest submissions of the current branch
$ git reflog
8. Remote Synchronization
# Download all changes to remote warehouse
$ git fetch [remote]
# Display all remote warehouses
$ git remote -v
# Display information about a remote warehouse
$ git remote show [remote]
# Add a new remote warehouse and name it
$ git remote add [shortname] [url]
# Retrieve changes to remote warehouses and merge with local branches
$ git pull [remote] [branch]
# Upload local designated branch to remote warehouse
$ git push [remote] [branch]
# Force the current branch to a remote warehouse, even if there is a conflict
$ git push [remote] --force
# Push all branches to remote warehouse
$ git push [remote] --all
Nine, revocation
# Restore the specified files in the temporary area to the workspace
$ git checkout [file]
# Restore a commit's specified file to the temporary and workspace
$ git checkout [commit] [file]
# Restore all files in the temporary storage area to the workspace
$ git checkout .
# Reset the specified file for the temporary area, consistent with the previous commit, but the workspace remains unchanged
$ git reset [file]
# Reset the temporary and workspace, consistent with the previous commit
$ git reset --hard
# The pointer to reset the current branch is the specified commit, while resetting the temporary area, but the workspace remains unchanged
$ git reset [commit]
# Reset the HEAD of the current branch as the specified commit, while resetting the temporary and workspace, consistent with the specified commit
$ git reset --hard [commit]
# Reset the current HEAD as the specified commit, but leave the temporary and workspace unchanged
$ git reset --keep [commit]
# Create a new commit to undo the specified commit
# All changes in the latter will be offset by the former and applied to the current branch.
$ git revert [commit]
# Remove uncommitted changes temporarily and move in later
$ git stash
$ git stash pop
Ten, others
# Generate a compression package for publication
$ git archive
Git It's a very powerful distribution version control System. It is not only suitable for managing the source code of large open source software, but also has many advantages in managing private documents and source code.
Git Common Operating Commands:
1) Relevant commands of remote warehouse
Check-out warehouse: $git clone git://github.com/ jQuery/jquery.git
View remote warehouse: $git remote-v
Add remote warehouse: $git remote add [name] [url]
Delete remote warehouse: $git remote rm [name]
Modify remote warehouse: $git remote set-url --push [name] [newUrl]
Draw remote warehouse: $git pull [remoteName] [local BranchName]
Push remote warehouse: $git push [remoteName] [local BranchName]
* If you want to submit a local branch test to a remote warehouse, and act as the master branch of the remote warehouse, or as another branch called test, as follows:
git push origin test:master // Submit local test branch as remote master branch
git push origin test:test *// Submit local test branch as remote test branch
Git push-f// Force push all files under a branch
2) branch operation related commands
View local branches: $git branch
View remote branches: $git branch-r
Create a local branch: $git branch [name] - Note that the new branch will not automatically switch to the current branch after it is created
Switching branches: $git checkout [name]
Create a new branch and switch to it immediately: $git checkout-b [name]
Delete branches: $git branch - D [name] - --- D option can only delete branches that have participated in the merge, but cannot delete branches that have not been merged. If you want to force a branch to be deleted, you can use the - D option
Merge Branches: $git merge [name] - Merge Branches named [name] with Current Branches
Create a remote branch (local branch push to remote): $git push origin [name]
Delete remote branches: $git push origin: heads /[name] or $git push origin: [name]
* Create empty branches: (remember to submit changes to your current branch before executing the command, otherwise it will be forced to delete without regret)
$git symbolic-ref HEAD refs/heads/[name]
$rm .git/index
$git clean -fdx
3) Version (tag) operation related commands
View version: $git tag
Create version: $git tag [name]
Deleted version: $git tag-d [name]
View the remote version: $git tag-r
Create a remote version (local version push to remote): $git push origin [name]
Delete remote version: $git push origin: refs/tags/[name]
Merge tag s from remote warehouses to local: $git pull origin --tags
Upload local tag s to remote warehouses: $git push origin --tags
Create annotated tag: $git tag - a [name] - M'yourMessage'
4) Submodule related operation commands
Add submodules: $git submodule add [url] [path]
For example: $git submodule add git://github.com/soberh/ui-libs.git src/main/webapp/ui-libs
Initialization sub-module: $git submodule init -- run only once when the warehouse is first checked out
Update submodule: $git submodule update -- run every time you update or switch branches
Delete sub-modules: (4 steps)
1) $ git rm --cached [path]
2) Edit the'.gitmodules'file and delete the relevant configuration nodes of the sub-module
3) Edit the'.git/config'file and delete the relevant configuration nodes of the sub-module
4) Manual deletion of directories remaining in sub-modules
5) Ignore some files and folders that are not submitted
Create a file named ". gitignore" in the warehouse root directory and write to unnecessary folder names or files. Each element takes up one line, such as
target
bin
*.db
=====================
Common Git commands
git branch Views All Local Branches
git status view current status
git commit submission
git branch -a Views all branches
git branch -r to view all local branches
Git commit-am "init" submitted and annotated
git remote add origin git@192.168.1.119:ndshow
git push origin master pushes files to the server
git remote show origin displays resources in remote library origin
git push origin master:develop
git push origin master:hb-dev associates local libraries with libraries on the server
git checkout --track origin/dev switch to remote dev branch
Git branch-D master development deletes local library development
Git checkout-b dev establishes a new local branch dev
git merge origin/dev merges branch dev with current branch
git checkout dev switch to local dev branch
git remote show view remote library
git add .
git rm File Name (including Path) Deletes the specified file from git
git clone git://github.com/schacon/grit.git pulls the code down from the server
git config --list to see all users
git ls-files to see what has been submitted
git rm [file name] deletes a file
Git commit-a submits all changes to the current repos
git add [file name] add a file to git index
Git commit-v You can see commit differences when you use the-v parameter
Git commit-m "This is the message describing the commit" to add commit information
Git commit-a-a is for add, add all change s to git index and commit it again
Git commit-a-v general submission order
Look at your commit log in git log
git diff to view updates that have not yet been temporarily saved
git rm a.a Remove Files (Deleted from Temporary and Workspace)
git rm --cached a.a removes files (only from the temporary area)
Git commit-m "remove" removes files (delete from Git)
Git rm-f.a. Forces the removal of modified files (deleted from temporary and workspace)
git diff --cached or $git diff -- stage to view uncommitted updates
git stash push gives the file to push into a temporary space
git stash pop pops files from temporary space
---------------------------------------------------------
git remote add origin git@github.com:username/Hello-World.git
git push origin master submits the local project to the server
-----------------------------------------------------------
git pull local and server-side synchronization
-----------------------------------------------------------------
The git push (remote warehouse name) pushes the local branch to the server.
git push origin serverfix:awesomebranch
------------------------------------------------------------------
git fetch is equivalent to remotely retrieving the latest version to the local, and does not automatically merge
Git commit-a-m "log_message" (-a is to submit all changes, -m is to add log information) local modifications are synchronized to the server side:
Git branch_0.1 master creates branch_0.1 branch from master
Git branch-m branch_0.1 branch_1.0 renames branch_0.1 to branch_1.0
git checkout branch_1.0/master switch to branch_1.0/master branch
du -hs
-----------------------------------------------------------
mkdir WebApp
cd WebApp
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@github.com:daixu/WebApp.git
git push -u origin master
Git Common Command Chart
--by zzuwenjie 2017-2-13