Home >Web Front-end >JS Tutorial >Summary of common Git commands
Remote warehouse related commands
Check out the warehouse: $ git clone git://github.com/jquery/jquery.git
View the remote warehouse: $ git remote -v
Add remote repository: $ git remote add [name] [url]
Delete remote repository: $ git remote rm [name]
Modify remote repository: $ git remote set- url --push [name] [newUrl]
Pull the remote warehouse: $ git pull [remoteName] [localBranchName]
Push the remote warehouse: $ git push [remoteName] [localBranchName]
*If you want to submit a local branch test to the remote warehouse and use it as the master branch of the remote warehouse, or as another branch named test, as follows:
$git push origin test:master //Submit the local test branch as the remote master branch
$git push origin test:test //Submit the local test branch as the remote test branch
Initialize the local git warehouse (create a new warehouse)
git init
Configure user name
git config --global user.name "xxx"
Configuration email
git config --global user.email "xxx@xxx.com"
git status and other commands automatically color
git config --global color.ui true
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto
clone remote warehouse
git clone git+ssh://git@192.168.53.168/VT.git
Branch operation related commands
View local branches: $ git branch
View the remote branch: $ 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
Switch branches: $ git checkout [name]
Create a new branch and switch to the new branch immediately: $ git checkout -b [name]
Delete a branch: $ git branch -d [name] ---- The -d option can only delete branches that have participated in the merge, and cannot delete branches that have not been merged. If you want to force delete a branch, you can use the -D option
Merge branch: $ git merge [name] ----Merge the branch named [name] with the current branch
Create Remote branch (local branch pushed to remote): $ git push origin [name]
Delete remote branch: $ git push origin :heads/[name] or $ gitpush origin :[name]
*Create an empty branch: (Remember to submit the modifications to your current branch before executing the command, otherwise it will be forcibly deleted without regrets)
$git symbolic-ref HEAD refs/ heads/[name]
$rm .git/index
$git clean -fdx
View the current version status (whether modified)
git status
Add xyz file to index
git add xyz
Add all changed files in the current subdirectory to index
git add .
Commit
git commit -m 'xxx'
Merge the last commit (for repeated modifications)
git commit --amend -m 'xxx'
Combine add and commit in one step
git commit -am 'xxx'
Delete files in index
git rm xxx
Recursive deletion
git rm -r *
Display commit Log
git log
Display 1 line of log -n is n line
git log -1
git log -5
##Display the commit log and related change files
git log --stat
#Display the details of a commit
git show dfb02e6e4f2f7b573337763e5c0013802e392818
You can only use the first few digits of the commitid
git show dfb02
Display HEAD commit log
git show HEAD
Display HEAD The commit log of the parent (previous version) ^^ is the previous two versions ^5 is the previous 5 versions
git show HEAD^
display Existing tag
git tag
Add v2.0 tag
git tag -a v2.0 - m 'xxx'
Show v2.0 logs and details
git show v2.0
Display v2.0 log
git log v2.0
Display all changes that have not been added to the index
git diff
Display all changes that have been indexed but not yet committed
git diff --cached
Compare with the previous one Version difference
git diff HEAD^
Compare the difference with the HEAD version lib directory
git diff HEAD -- ./lib
Compare the remote branch master to the local branch master that is not present
git diff origin/master..master
Only displays the difference files, not the specific content
git diff origin/master..master --stat
Add remote Definition (for push/pull/fetch)
git remote add origin git+ssh://git@192.168.53.168/VT.git
Show local branch
git branch
Show branch containing commit 50089
git branch --contains 50089
Show all branches
git branch -a
Show all original branches
git branch -r
Displays all branches that have been merged into the current branch
git branch --merged
Display all branches that have not been merged into the current branch
git branch --no-merged
Local branch rename
git branch -m master master_copy
Create a new branch master_copy from the current branch and checkout
git checkout -b master_copy
Full version of the above
git checkout -b master master_copy
Check out the existing features/performance branch
git checkout features/performance
Check out the remote branch hotfixes/BJVEP933 and create a local tracking branch
git checkout --track hotfixes/BJVEP933
Checkout version v2.0
git checkout v2.0
Create a new local branch from the remote branch develop devel and checkout
git checkout -b devel origin/develop
Check out the README file of the head version (can be used to modify error rollback)
git checkout -- README
Merge the remote master branch to the current branch
git merge origin/master
Merge the changes to commit ff44785404a8e
git cherry-pick ff44785404a8e
Push the current branch to the remote master branch
git push origin master
Delete the hotfixes/BJVEP933 branch of the remote warehouse
git push origin :hotfixes/BJVEP933
Push all tags to the remote repository
git push --tags
Get all remote branches (do not update local branches, Merge is required)
git fetch
Get all original branches and clear deleted branches on the server
git fetch --prune
Get the remote branch master and merge it to the current branch
## Rename the file README to README2git pull origin master
git mv README README2
Reset the current version to HEAD (usually used for merge failure rollback)
git reset --hard HEAD##Delete branch hotfixes/BJVEP933 (modifications of this branch have been merged into other branches)git rebase
git branch -D hotfixes/BJVEP933Force deletion of branch hotfixes/BJVEP933
git ls-filesList the files included in git index
git show-branchIllustration of the current branch history
Illustrated history of all branches
Show the file modifications corresponding to the submission history
##git revert dfb02e6e4f2f7b573337763e5c0013802e3 92818
Internal command: display a certain git object
git ls-tree HEAD
Internal command: display a certain ref for SHA1 HASH
git rev-parse v2.0
Show all commits, including orphaned nodes
git reflog
git show HEAD@{5}
git show master@{yesterday}
Image submission log
git log --pretty=format:'%h %s' --graph
git show HEAD~3
git show -s --pretty=raw 2be7fcb476
Store the current modifications and move all to HEAD status
git stash
View all temporary saves
git stash list
Refer to the first stash
git stash show -p stash@{0}
Apply the first stash
git stash apply stash@{0}
Search for the text "delete from" in the file
git grep "delete from"
git grep -e '#define' --and -e SORT_DIRENT
git gc
git fsck
The above is the detailed content of Summary of common Git commands. For more information, please follow other related articles on the PHP Chinese website!