Common commands of team development tool git

Keywords: Java git github vim Mac

Common Git commands

Git configuration

git config --global user.name "storm"
git config --global user.email "stormzhang.dev@gmail.com"
git config --global color.ui true
git config --global alias.co checkout  # alias
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.br branch
git config --global core.editor "vim"  # Setting up Editor to use vim
git config --global core.quotepath false # Set Display Chinese File Name

User's git configuration file ~/.gitconfig

Common Git commands

View, add, submit, delete, retrieve, reset modified files

git help <command>  # Display command help
git show            # Display the content of a submission
git show $id

git co  -- <file>   # Discard workspace modifications
git co  .           # Discard workspace modifications

git add <file>      # Submit working document modification to local temporary storage area
git add .           # Submit all modified working documents to the temporary storage area

git rm <file>       # Delete files from version Libraries
git rm <file> --cached  # Delete files from version libraries, but do not delete files

git reset <file>    # Restore from Temporary Zone to Working Document
git reset -- .      # Restore from Temporary Zone to Working Document
git reset --hard    # To restore the status of the last submission, i.e. to abandon all the changes made since the last submission

git ci <file>
git ci .
git ci -a           # Combine operations such as git add, git rm and git ci
git ci -am "some comments"
git ci --amend      # Modify the last submission record

git revert <$id>    # Restore the status of a submission, and the restore action itself creates a submission object
git revert HEAD     # Restore the status of the last submission

View the file diff

git diff <file>     # Compare the differences between current and temporary files
git diff
git diff <$id1> <$id2>   # Compare the differences between two submissions
git diff <branch1>..<branch2> # A comparison between two branches 
git diff --staged   # Comparing Temporary Zone and Version Library Differences
git diff --cached   # Comparing Temporary Zone and Version Library Differences
git diff --stat     # Simply compare statistics

View submission records

git log
git log <file>      # View this file for each submission record
git log -p <file>   # View diff for each detailed change
git log -p -2       # Check out the last two details

tig

On Mac, you can use tig instead of diff and log, brew install tig

Git Local Branch Management

View, switch, create and delete branches

git br -r           # View remote branches
git br <new_branch> # Create new branches
git br -v           # View the final submission information for each branch
git br --merged     # View branches that have been merged into the current branch
git br --no-merged  # View branches that have not yet been merged into the current branch

git co <branch>     # Switch to a branch
git co -b <new_branch> # Create a new branch and switch to the past
git co -b <new_branch> <branch>  # Creating a new_branch based on branch

git co $id          # Check out a history submission record, but there is no branch information. Switching to other branches will automatically delete it.
git co $id -b <new_branch>  # Create a branch by checking out a history submission record

git br -d <branch>  # Delete a branch
git br -D <branch>  # Mandatory deletion of a branch (mandatory deletion of unincorporated branches)

Branch merging and rebase

git merge <branch>               # Merge branch branches to the current branch
git merge origin/master --no-ff  # Do not merge Fast-Foward to generate merge submissions

git rebase master <branch>       # A master rebase to a branch is equivalent to:
git co <branch> && git rebase master && git co master && git merge <branch>

Git patch management (for developing synchronization on multiple machines)

git diff > ../sync.patch         # Generate patches
git apply ../sync.patch          # Patch up
git apply --check ../sync.patch  # Test whether the patch is successful

Git Temporary Storage Management

git stash                        # Temporary storage
git stash list                   # Column all stash
git stash apply                  # Restore temporary contents
git stash drop                   # Delete temporary storage area
git stash clear

Git Remote Branch Management

git pull                         # Grab all branch updates of remote warehouse and merge them locally
git pull --no-ff                 # Grab all branch updates of remote warehouse and merge them locally. Do not merge them fast.
git fetch origin                 # Grab Remote Warehouse Updates
git merge origin/master          # Merge remote primary branch to local current branch
git co --track origin/branch     # Tracking a remote branch to create a local branch
git co -b <local_branch> origin/<remote_branch>  # Create local branches based on remote branches, with the same function

git push                         # All branches of push
git push origin master           # Push local main branch to remote main branch
git push -u origin master        # Push the local main branch to remote (if no remote main branch is created to initialize the remote warehouse)
git push origin <local_branch>   # Create a remote branch, origin is the name of the remote warehouse
git push origin <local_branch>:<remote_branch>  # Create a remote branch
git push origin :<remote_branch>  #First delete the local branch (git br-d < branch >), then push to delete the remote branch

Git Remote Warehouse Management

git remote -v                    # View Remote Server Address and Warehouse Name
git remote show origin           # View the status of remote server repository
git remote add origin git@github:stormzhang/demo.git         # Add remote warehouse address
git remote set-url origin git@github.com:stormzhang/demo.git # Setting up remote warehouse address (for modifying remote warehouse address)

Create a remote warehouse

git clone --bare robbin_site robbin_site.git  # Creating a pure version repository with versioned projects
scp -r my_project.git git@git.csdn.net:~      # Upload pure warehouse to server

mkdir robbin_site.git && cd robbin_site.git && git --bare init # Create a pure warehouse on the server
git remote add origin git@github.com:robbin/robbin_site.git    # Setting up remote warehouse address
git push -u origin master                                      # First submission by client
git push -u origin develop  # For the first time, submit the local development branch to the remote development branch, and track

git remote set-head origin master   # Setting up the HEAD of the remote warehouse to point to the master branch

You can also command to set up tracking remote libraries and local libraries

git branch --set-upstream master origin/master
git branch --set-upstream develop origin/develop

Posted by ramas on Tue, 29 Jan 2019 15:21:14 -0800