git clone git@github.com:iwz2099/test.git
cdtesttouch README.md
git add README.md
git commit -m "add README"git push -u origin master
#The above command pushes the local master branch to the remote origin branch. At the same time, -u specifies the default remote branch name of the current warehouse as origin. You can use git push without any parameters later#Push all local branches to the origin hostgit push -u origin --all
#If the local development is based on the case_dev_wanzi branch, push to the remote case_dev branchgit push origin case_dev_wanzi:case_dev
git status #Query the current branch status informationgit log #View the current branch commit informationgit log -n3 #Query the last three commitsgit log -p -2 #Query the content difference of each commit, only display the last two commit records,git log --stat #Query the resume statistics of each commitgit log --pretty=oneline #Display the information of each commit in one line, oneline can be short, full, fullergit log --pretty=format:"%h - %an, %ar : %s"git log --pretty=format:"%h %s" --graph #ASCII string to visualize your branch and merge historygit reflog #Display all branch operation information (including commit, reset and deleted commit)git reflog #Display the last 10 logsgit grep -n wanzi #Search the commit history and working directorygit grep --count wanzi #Search display timesgit clean #Remove untracked files that are not ignoredgit clean -d #Clean up the working directorygit clean -d -n #-n tests the cleanup of the working directory, but it is not actually cleaned up
git branch #View the current branchgit branch -v #View the last commit of each branch#Create a local dev branch based on the remote master branchgit checkout -b dev origin/master
git branch --merged #View which branches are merged into the current branchgit branch --no-merged #View which branches have not yet been merged into the current branch#Develop a new feature, -b create a branch, and switch to the newly created branchgit checkout -b dev-20180720-111111-wanzi
Equivalent to:
git branch r-20180720-111111-wanzi
git checkout r-20180720-111111-wanzi
Merge the post-development feature into the Master trunk
git checkout master
git merge dev-20180720-111111-wanzi
Git merge operation
Create a new branch issue54 based on the remote master, and develop the project based on this branch
git fetch origin #Pull away the difference informationgit merge origin/master #Merge the remote branch into the current projectgit push origin master #Push code to the remote branchgit log --no-merges issue54..origin/master #Check which information in master is not merged into the issue54 branch
git tag #List the tag information of the current projectgit tag -l 'wanzi-2018*'#-l can also list only your own branchesgit tag v1.8-20180720 #Create a tag (usually temporary)git tag -a v1.8-20180720 -m 'wanzi version 1.8'#-a creates a tag, -m adds a description, and the tag information will be storedgit show v1.8-20180720 #View the tag information. At this time, you can compare the difference between git tag -a and git taggit push origin tag_name #Push tags to remote warehousesgit push origin --tags #Push many tags to remote warehouses at one timegit push origin :tag_name #Delete remote tag informationgit checkout -b dev-20180720-111111-wanzi v1.2.0 #Create a new tag version based on a branchgit branch -D dev-20180720-123333-wanzi #Forced deletion of an unmerged branch
#A coder creates a new branch feature1 based on the remote mastergit checkout -b feature1 origin/master
#B coder creates a new branch feature11 based on the remote mastergit checkout -b feature11 origin/master
#A coder finishes development first and pushes the code to the feature1 branch of the remote service. Coder B finishes development later and wants to merge the modified information into feature1git fetch origin
git merge origin/feature1
git push -u origin feature11:feature1
Git cancels files in the temporary storage area and cancels file modifications
#Git add the code to the cache area, but does not commit it, roll back the codegit reset HEAD . or
git reset HEAD a.txt
This command only changes the staging area, not the workspace, which means that without any other operations, the actual files in the workspace remain unchanged from before the command was run
git checkout -- . #Cancel all changes to the path and return to the last commit versiongit checkout -- a.txt #Cancel all changes to a.txt and return to the last commit version
git log
git reset --hard <commit_id> #Rollback to the commit id of a commitgit reset --hard HEAD^ #Rollback to the previous versiongit reset --hard HEAD^^ #Rollback to the second to last versiongit reset --hard HEAD~4 #Rollback to the fourth to last versiongit push origin HEAD --force #Force a commit, and the previous wrong commit will be deleted from the remote repository (be careful when you have project management permissions)
Git rollback master code to a tag version
Based on release tag creates a temporary rollback branch and pushes the branch to the remote master