Git command sorting

Source: Internet
Author: User
Tags git commands git mergetool

Although git has been used for a long time, only a few limited commands have been used. Recently, I spent two days sorting out the GIT commands that may be used in my work and put them here for future reference:

The GIT tool mainly includes the following commands:
Version configadd // staging (cache) is currently modified to index (cache) Am // apply + commit, apply patches and commitapply // apply patchbranch // For branch management, including creating and deleting, rename and other common operations such as checkout // used for Branch switching clone // copy repositorycommit // submit and modify diff // compare tool fetch // obtain the remote Branch's modified format-patch // generate patchinit // initialize gitlog // view logmv // rename pull // fetch + merge, get the modification of the remote branch and merge the modification of the current branch to the remote repositoryrebase // reset the base reset // cancel the specified commit, or cancel stagerevert // reverse commit RM // delete the file, and add the delete file operation to the stage show // view commit, tag and other details stash // a cache mechanism Status // view git status gitk // graphical interface to view all the COMIT of the current branch, similar to the gitlog GUI version
Most git commands require the current directory (or the ancestor directory of the current directory) to exist. the GIT folder can be executed only in the following situations: 1. git config -- Global xxxx // git global settings 2. git init // initialize git3. git clone // copy Repository
The following are some useful commands and parameters: git config [-- Global] user. name xxx // set the user's life git config [-- Global] user. email XXX // set the user's mailbox git config [-- Global] color. ui auto // set the color scheme to auto
Git init -- bare // initialize a git repository. The repository is a bare library and does not contain a work tree (that is, this repository is only used as a server and does not provide the editing function by default ).
PS: This command does not create the. Git folder in the current directory, but generates the branches, hooks, info, objects, refs folder, and config, description, and head files. In fact, the content is in the. Git folder. Because the bare library is not a workspace, git displays the content instead of hiding it in the. Git folder.
PS: the key to determining whether a repository is a bare library is the core. Bare attribute (Boolean attribute ). You can set the core. Bare attribute by using the GIT config command or by modifying the config file.
Git remote add origin SSH: // xxxxxx // Add remote
Git status // view the status of three files: untracking (files not included in version control) and unstaged (files included in version control but not saved to index ), staged (saved to index)
Git init // create a. Git folder in the root directory to include the files in the current directory into git management.
Git clone SSH: // xxxxxxx [-B master] // copy repository to local PS:-B parameter can specify the branch. Git will create the specified branch with the same name locally, and the corresponding branch on the track origin. PS: If the-B parameter is not specified, git will create a branch with the same name as the current branch on the Origin locally and establish a trach relationship.
Git branch // view local branch git branch-r // view remote branch git branch-A // view all branches (including local and remote branches) git branch-AVV // view all branches, and display the track relationship git branch master // create master molecule git branch MV master1 master2 // rename master1 branch to master2 branch git branch [-d |-D] Master // Delete master Branch, -D: Force Delete git Branch -- track origin/master // create a master Branch, which tracks the master branch on the origin server
Git check out Master // check out Master branch git checkout -- track origin/master-B master // git Branch -- track origin/master + checkout mastergit checkout <File> // resume work tree to head, staged modifications will be retained by git checkout. // restore all changes made to the version control file to the head. changes made to the staged file will be retained.
Git add 123.txt // modify the 123.txt file to the index. If 123.txtis untrack(123.txt is a new file, which is not included in version control), add a new record to the index. Git Add. // Add all new in the current directory, and modify modeminto index.
Git RM 123.txt // Delete the 123.txt file and add the delete record to the index.
Git commit // submit git commit-A in the stage // git add. + git commitgit commit-M "XXXXX" // use the specified information as the log. If the-M parameter is not specified, enable IM (Vim ?) Enter loggit commit-am "XXXXX" // git commit-a-m "XXXXX"
Git diff <File Name> // compare the difference between the current work tree and index git diff -- chached // compare the difference between the current index and the head git diff -- staged // same -- chachedgit giff <comit1> <commit2> // compare the differences between two commit
Git push [-u] origin master // push the modification on the current branch to the master branch of the origin. The-u parameter is optional. You can establish a tracking relationship. After one execution, git push can be used to push and modify git push without meals // according to the tracker relationship, push and modify to the remote end
Git pull origin master // extract origin modifications to the current local branch git pull // extract remote modifications based on the tracker relationship and merge to the current Branch
Git revert head ~ 3 // reverse commit the latest 4th commit (reverse the latest commit to git revert head) git revert head commit1 commit2 // reverse commit commit1 and commit2git revert head commit1 .. commit2 // reverse commit commitps between commit1 (not included) and commit2 (included): reverse commit refers to generating a new commit, the content of this commit is opposite to that of the specified commit.
Git reset // return the changes in the index to the work tree, which is equivalent to the reverse operation of git Add. and does not affect the content of the file git reset -- soft head ~ In the Work tree ~ 2 // cancel all the commit since the last 2nd commit times and save the modification to the commit in the index. The worktree will not be affected by git reset -- hard head ~ 2 // cancel all commit since the last 2 commit, clear the index, and restore the work tree to the status after the last 3rd commit.
Git stash // Save the changes to the current work tree and the changes to the index, and restore the work tree to the head state. Git stash pop // extract and apply the changes saved in stash to git stash clear // clear the cached stash changes
Git rebase master test // reset the master branch to the test branch by performing the following steps: 1. first, find the last commit0, 2. restore the master branch to the state of commit0, save all commit3. on the master branch, start from commit0, and apply all commit of the test branch from commit0 to the master branch. apply all the commit from commit0 on the master branch that you just saved to the master branch in turn. Details: http://www.cnblogs.com/kym/archive/2010/08/12/1797937.html
Git merge test // merge the test branch to the current Branch
Git mergetool // call the merge tool to solve conflictsps: The mergetool command will call the tool specified by merge. tool, which can be set using git config
Git format-patch-1 // generate the patchgit format-patch master of the latest commit // generate a commit patch that is present on all current branches but not on the master
Git am <patch-File> // apply the patch file and commitps: If you execute git am <patch-File>, previous rebase directory occurs .. /. git/rebase-apply still exists but mbox given error. You can run git am -- abort before running git AM









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.