Summary of common git commands and common git commands

Source: Internet
Author: User
Tags git commands git revert commit

Summary of common git commands and common git commands
Git command git configuration (config ):

Git version # view the version git config-l # view the current configuration git config -- global user. name "Dean" # Set the user name and email git config -- global user. email g.xiangyu1990@gmail.com # Set User Name, mailbox git config -- global alias. ci commit # Set git command alias git config -- global alias. co checkout # Set the git command alias
Git repository (repository ):
# Create a local git repository and name it: git init demo # clone a remote git repository to the specified path: git clone https://github.com/a396901990/android.git/path/workpsace
Git branch (branch ):
Git branch # view branch git remote show origin # view all branches git branch <branchname> # create a new branch git checkout <branchname> # Switch to branch git checkout-B <new_branch> # create and switch to the new branch git branch-d <branchname> # Delete the branch (-D strong delete) git branch-m <old> <new> # rename a local branch
Add git ):
Git add <file> # add a locally specified file name or directory (added or modified, not deleted) to the temporary storage zone git add. # add all local (new and modified, not deleted) files to the temporary storage area git add-u # local (modified and deleted, not added) add the file to the temporary storage area git add-A # add all local changes to the temporary storage area (git add-A = git add. + git add-u) git add-I # open an interactive interface and add files as needed
Git delete/Rename (rm/mv ):
Git rm <file> # delete the file git rm-r <floder> # Delete the folder git rm -- cached <file> # delete the file from the version library, but do not delete the file git mv <old_name> <new_name> # rename the file
Git commit (commit ):
Git commit-m "comment" # submit the content in the temporary storage area (added) and add the comment git commit-a # add the modified file to the temporary storage area (excluding the new (untracked) file), and then submit. Git commit -- amend # modify the committed commit (no push) git commit -- amend-m "comment" # modify the commit Annotation
Git difference (diff ):
Git diff # view the difference between the index in the working directory (working tree); git diff -- cached # view the temporary files (stages) and do not submit (commit) difference: git diff -- staged # Same as git diff HEAD # view the difference after the last commit (HEAD indicates the information of the last commit) git diff -- stat # view and display the simple results (file list) git diff commit1 commit2 # Compare the content submitted twice (or branch, hash value)
Git view history (log ):
Git loggit log-3 # view the git log -- oneline of the first three changes # display a loggit log-p in a row # view the details of the changes git log -- stat # view the submitted statistics git log -- graph # shows when branch and merge information appears.
Git status ):
Git status # view the status of your code in the cache and the current working directory git status-s # output the result in a brief form: git status -- ignored # display the ignored File
Git storage (stash ):
Git stash # save the current working progress git stash save "message" # save progress add git stash list # display the progress list git stash pop # restore the latest working progress, delete git stash apply from the storage list # restore the latest save progress, but do not delete git stash drop # delete a progress, delete the latest git stash clear by default # delete all
Git reset (reset ):
Git reset -- mixed # unlike git reset without any parameters, it resets the temporary storage zone, but does not change the git reset -- soft # In the workspace to a specific version, git reset -- hard # Roll back to a specific version without changing the temporary storage area and workspace (if you need to submit it, just commit it) to replace the temporary storage area and workspace, the local source code will also change to the content of the previous version git reset # Remove the content previously added to the temporary storage area by using the git add command from the temporary storage area (equivalent to the reverse operation of git add-) git reset HEAD # The HEAD effect is the same as above, because the reference is reset to HEAD, which is equivalent to not resetting git reset filename # removing the file from the temporary storage area (equivalent to the reverse operation of git add filename) git reset HEAD ^ # reference rollback once (the workspace remains unchanged, the temporary storage area is rolled back) git reset -- soft HEAD ~ 3 # reference rollback three times (the workspace remains unchanged, and the temporary storage area remains unchanged)
Git undo (revert ):
Git revert commit # undo specified commitgit revert HEAD # undo the previous commitgit revert-no-edit HEAD # undo the last time and directly use the default comment git revert-n HEAD # undo the previous but not commit
Git merge (merge ):
Git merge <branch_name> # merge git merge -- no-ff <branch_name> # Use the no fast forward merge method, this method will generate a new commitgit merge -- abort # Roll Back To The status before merge (may fail) while merging)
Rebase ):
Git rebase <branch_name> # git rebase -- continue # After the rebase is executed and the conflict is resolved, execute this command to continue the application (apply) the remaining patch git rebase -- skip # skips the current commit git rebase -- abort # terminates rebase, and the branch returns to the status before rebase starts.
Git get/pull (fetch/pull ):
Git fetch # Get the latest version from a remote location to the local location without automatic mergegit pull # Get the latest version from the remote location and merge to the local git pull -- rebase # Save local changes and merge the latest remote changes, merge local changes that have just been saved (do not generate useless merge synchronization)
Git push ):
Git push origin master # push the local branch to the master branch of the origin host git push-u origin master #-u specify the origin as the default host, you can use git to push-f origin #-f without adding any parameters, generate a non-straight forward merge (non-fast-forward merge) git push -- all origin # push all local branches to the origin master

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.