Git common commands

Source: Internet
Author: User
Tags file diff git commands
Gitconfig -- globaluser. name & quot; robbin & quot; gitconfig -- globaluser. email & quot; fankai@gmail.com & quot; Git configuration

Git config -- global user. name "robbin" git config -- global user. email "fankai@gmail.com" git config -- global color. ui truegit config -- global alias. co checkoutgit config -- global alias. ci commitgit config -- global alias. st statusgit config -- global alias.br branchgit config -- global core. editor "mate-w" # set Editor to use textmategit config-l # List all configurations

User's git configuration file ~ /. Gitconfig

Common Git commands
View, add, submit, delete, retrieve, and reset the modified file

Git help# Show command helpgit show # display the submitted content git show $ idgit co --
 
  
# Abandon the workspace and modify git co. # discard the workspace and modify git add
  
   
# Submit the work file modification to the local temporary storage area git add. # submit all the modified work files to the temporary storage area git rm.
   
    
# Delete the file git rm from the version Library
    
     
-- Cached # delete the file from the version library, but do not delete the file git reset
     
      
# Recovering from the temporary storage area to the working file git reset --. # recovering from the temporary storage area to the working file git reset -- hard # recovering the last submitted state, that is, giving up all the changes made this time after the last submitted git ci
      
        Git ci. git ci-a # add git, git rm and git ci are combined for git ci-am "some comments" git ci -- amend # modify git revert for the last commit record <$ id> # Restore a record submitted status, the Restore action itself also creates a commit object git revert HEAD # restore the last commit state
      
     
    
   
  
 

View the file diff

Git diff
 
  
# Compare the differences between the current file and the saved space file git diffgit diff <$ id1> <$ id2> # compare the differences between the two commits git diff
  
   
..
   
    
# Compare git diff -- staged # compare the differences between the staging zone and the version Library git diff -- cached # compare the differences between the staging zone and the version Library git diff -- stat # only compare the statistics
   
  
 

View submission records

Git loggit log
 
  
# View the git log-p record of this file each time
  
   
# View the diffgit log-p-2 for each detailed modification # view the diffgit log -- stat # for the last two detailed modifications
  
 

Tig
On Mac, the diff and log can be replaced by tig, and brew install tig.

Git local branch management
View, switch, create, and delete branches

Git br-r # View remote branch git br
 
  
# Create a new branch git br-v # view the final commit information of each branch git br -- merged # view the branch git br that has been merged to the current branch -- no-merged # check that it has not been git co
  
   
# Switch to a branch git co-B
   
    
# Create a new branch and switch to git co-B
     
     
      
# Create a new new_branchgit co $ id based on branch # checkout a historical commit record without branch Information. switching to another branch will automatically delete git co $ id-B
      
        # Checkout a historical commit record and create it as a branch git br-d
       
         # Delete a branch git br-D
        
          # Force delete a branch (force delete a branch that has not been merged)
        
       
      
     
    
   
  
 

Branch merge and rebase

Git merge
 
  
# Merge branch branches to the current branch git merge origin/master -- no-ff # Do not merge Fast-Foward, so that you can generate merge to submit git rebase master
  
   
# Rebase the master database to branch, which is equivalent to: git co
   
    
& Git rebase master & git co master & git merge
    
   
  
 

Git patch management (convenient for development and synchronization on multiple machines)

Git diff> ../sync. patch # Generate the patch git apply ../sync. patch # patch git apply -- check ../sync. patch # test whether the patch is successful

Git temporary management

Git stash # temporary git stash list # list all stashgit stash apply # Restore the temporary content git stash drop # Delete the temporary storage area

Git remote branch management

Git pull # capture updates of all branches in the remote repository and merge them to the local git pull -- no-ff # capture updates of all branches in the remote repository and merge them to the local machine, do not merge git fetch origin quickly # capture remote repository update git merge origin/master # merge remote master branch to local current branch git co -- track origin/branch # track a remote branch to create a corresponding git co-B
 
  
Origin/
  
   
# Create a local branch based on a remote branch, function same as git push # push all branches git push origin master # push the local master branch to the remote master branch git push-u origin master # push the local master branch to the remote (if there is no remote master branch then, used to initialize a remote repository) git push origin
   
    
# Create a remote branch. The origin is the remote repository name git push origin.
    
     
:
     
      
# Create a remote branch git push origin:
      
        # First delete the local branch (git br-d
       
         ), And then push to delete the remote branch.
       
      
     
    
   
  
 

Git remote repository management

Git remote-v # view the remote server address and repository name git remote show origin # view the remote server repository status git remote add origin git @ github: robbin/robbin_site.git # add remote repository address git remote set-url origin git@github.com: robbin/robbin_site.git # set remote repository address (used to modify remote repository address) git remote rm
 
  
# Deleting a remote repository
 

Create a remote repository

Git clone -- bare robbin_site robbin_site.git # Create a pure version repository scp-r my_project.git git@git.csdn.net with a version Project :~ # Upload pure repository to the server mkdir robbin_site.git & cd robbin_site.git & git -- bare init # Create a pure repository git remote add origin git@github.com on the server: robbin/robbin_site.git # set the remote repository address git push-u origin master # The client submits git push-u origin develop for the first time # submits the local develop branch to the remote develop branch for the first time, and trackgit remote set-head origin master # set the HEAD of the remote warehouse to point to the master branch

You can also set the remote and local databases for tracking.

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.