[Management tools] git version introduces and summarizes the common commands

1 git Introduction

What 1.1 git that?

  " The Git is a distributed version control software, and CVS, Subversion centralized version of a different type of control means, it uses a distributed repository approach does not require the server software, version control can operate, so that the source code publishing and communication is extremely convenient. "

1.2 git advantage  

   most of the operations done locally, without networking
   integrity assurance
   add data rather than delete or modify data as
   branch operation is very fast and smooth
  is fully compatible with the Linux command 

1.3 git structure

  

1.4 git and code hosting center 

  Task code hosting center: maintaining a remote repository
   LAN environment:
     gitlab server
   under extranet environment:
     GitHub
     cloud code

2 git commonly used commands

2.1 git init

     Initialize the local library.
  Effect: creates a .git folder in the current folder.
     Note: .git directory is stored in a local database associated subdirectories and files, do not delete, do not tinker.

2.2 git clone

     Get a url corresponding remote Git repo, create a local copy.
     The general format is git clone [url].
     clone down the repo will last a trailing slash url name names, create a folder, if you want to specify a specific name, you can git clone [url] newname specified.

2.3 git status

     View the work area, the buffer zone status.

2.4 git log

       Go reflog.
   show commit history of a branch.
     git log --oneline --number: show only one line each log displays number.
     git log --oneline --graph: can graphically shows the branch merge history.
     git log branchname log may display particular branch.
     git log --oneline branch1 ^ branch2, can be viewed in branch 1, but not in the branch submitted 2 ^ meant to exclude (with quotation marks may give ^ branch2 under Window) this branch.
     git log --decorate will show the tag information.
     git log --author = [author name] can commit history specify the author.
     git log --since --before --until --after screening log based on submission time.
     --no-merges the merge commits may be excluded.
     git log --grep filter according to a commit log: git log --grep = keywords
     By default, git log --grep --author OR relationship, that meet namely a return, if you want them to be relations AND, you can add --all-match of the option.
     git log -S: filter by introduced diff.
     For example: (Note that there is no separation between the equal sign and the following word S) git log -SmethodName.
     git log -p: show patch introduced at each commit.
     Each submission is a snapshot (snapshot), diff Git will each commit calculated as a patch show it to you.
     Another method is git show [SHA].
     git log --stat: show diffstat of changes introduced at each commit.
     Also look at the relative changes in the information, - stat simpler than some of the output -p.

2.5 git add [file name]

     The working area of ​​the "New / Edit" added to the staging area.

2.6 git diff

     No arguments git diff:
     show diff of unstaged changes.
     This command compares the differences between files and snapshot staging area in the current working directory, that is, after the modification has not been stored temporarily change the content.
 
     To see the difference between the files already stored temporarily snapshot of the last commit and can be used:
     git diff --cached command.
     show diff of staged changes.
     (Git 1.6.1 and later also allows git diff --staged, the effect is the same).
 
     git diff HEAD
     show diff of all staged or unstated changes.
     That all changes between relatively woking directory and the last commit.
 
     If you want to see all changes since a version of what you can use:
     git diff [version tag]
     Like log command, diff can also add parameters to simplify --stat output.
 
     git diff [branchA] [branchB] can be used to compare two branches.
     It actually returns a result from A to patch B, not what we want.
     Generally, we want the result after two separate branches are what their changes, is by the command:
     git diff [branchA] ... [branchB] given.
     In fact it is: git diff $ (git merge-base [branchA] [branchB]) [branchB] results.

2.7 git commit

     Add submission has been coming changes.
     git commit -m “the commit message"
     git commit -a will first of all have track changes to files add in, and then submit (a bit like the svn commit, without first staging). For there is no track of files, or need to git add it.
     git commit --amend supplement submitted. will use the parent submit the same to the current node for a new submission, the old submission will be canceled.
 

2.8 git reset

     undo changes and commits.
     Here HEAD keyword refers to the current branch most tip latest in a submission. That is the latest version of the repository on the branch.
     git reset HEAD: unstage files from index and reset pointer to HEAD
     This command is used to add into a file accidentally taken out from the staged state to be a separate operation for a file: git reset HEAD - - filename, the - - may not be added.
     git reset --soft
     move HEAD to specific commit reference, index and staging are untouched.
     git reset --hard
     unstage files AND undo any changes in the working directory since last commit.
     Use git reset -hard HEAD be reset, ie, after the last submission, changes will change the working directory and all staged disappearance, restore to the state the previous submission.
     HEAD here can be written in any SHA-1 once submitted.
     git with no parameters of soft and hard reset, in fact, with the default parameters mixed.
 
     to sum up:
     git reset --mixed id, is the git HEAD changed (that is, commit record changed), but the file has not changed (that is, working tree has not changed). canceled and add the content commit.
     git reset --soft id. In fact, after git reset -mixed id, and do a git add. that the abolition of the contents of the commit.
     git reset --hard id. is the git HEAD changed, the file has changed.
     Sort by change range is as follows:
     soft (commit) < mixed (commit + add) < hard (commit + add + local working)
 
2.9 git revert
     Reverse the revocation submitted. As long as the submission (commit) the wrong name (reference) as a parameter passed to the command on it.
     git revert HEAD: undo recent submission.
     git revert creates a new reverse submit, you can tell Git parameter -n Do not commit.
    

Go 2:10 rm

     git rm file: remove files from the staging area, and also remove the working directory.
     git rm --cached: remove files from the staging area, but stay in the working directory.
     git rm --cached functionally equivalent to git reset HEAD, clearing the cache, but do not move the working directory tree.
 

2.11 git clean

     git clean is to remove the file does not track from the working directory.
     The usual argument is git clean -df:
     -d representation while removing a directory, -f express force, because the git configuration file, clean.requireForce = true, if not -f, clean will be rejected.
 
2.12 mV Go
     git rm - - cached orig; mv orig new; git add new
 
2.13 git stash
     The current changes is pressed into a stack.
     git stash will all change in the current directory and index (but does not include not track files) pressed into a stack, and then leave you with a clean working condition, that is, in the last submitted at the latest.
     git stash list displays the list stack.
     git stash apply: remove one item (stash @ {0}) stash in, and applied to the current working directory.
     Other items can also be specified, such as git stash apply stash @ {1}.
     If you want to remove it while applying stash items, you can use git stash pop
 
     Delete stash of items:
     git stash drop: a delete, delete the specified parameters can also be specified in a project.
     git stash clear: remove all items.
 
2.14 git branch
     git branch branches can be used to list, create and delete branches branch.
     git branch -v can see every last submitted a branch.
     git branch: lists all local branches, the current branch will be marked out of asterisks.
     git branch (branchname): create a new branch (when you create a branch in this way, the branch is based on the submission of your establishment). 
     git branch -d (branchname): delete a branch.
     Delete remote branch:
     git push (remote-name) :(branch-name): delete a remote branch.
     This is because the full form of the command is:
     git push remote-name local-branch:remote-branch
     And here local-branch of the section is empty, it means delete remote-branch
 
2.15 git checkout
  git checkout (branchname)
  Switch to a branch.
     git checkout -b (branchname): Create and switch to a new branch.
     This command is git branch newbranch and git checkout newbranch together results.
     checkout has another role: to replace the local changes:
     git checkout --<filename>
     This command will replace your working file directory contents of the latest HEAD in. Added to the changes and the new file in the temporary area will not be affected.
     Note: git checkout filename deletes the file does not scratch and submit all changes, this operation is not reversible.
 
2.16 git go
     To merge into a branch of the current branch.
     git merge [alias]/[branch]
     The remote branches merge into the current branch.
 
     If a conflict arises, you need to manually modify, you can use git mergetool.
     When conflict resolution can be used git diff, adding with git add after resolving finished, it means that the conflict has been resolved.
 
2:17 git tag
     tag a point in history as import.
     Then will establish a permanent bookmark in a submission, usually issued a release version or ship something plus tag.
     For example: git tag v1.0
     git tag -a v1.0, -a parameter allows you to add some information, that make an annotated tag.
     When you run git tag -a command, Git will open a tag editor lets you enter information.
     
     We can use commit SHA to submit to a hit tag past:
     git tag -a v0.9 XXXX
 
     When push is not included in the tag, if you want to include, you can add --tags parameters when push.
     fetch time, branch HEAD can reach the tags are automatically fetch down, tags that are not reachable from branch heads will be skipped. If you want to make sure that all the tags are contained in, need to add --tags options.
 
2.18 git remote
     list, add and delete remote repository aliases.
     It is not necessary each time with a full url, so Git for each remote repo url to have an alias, and then use git remote to manage this list.
     git remote: 列出remote aliases.
     If you clone a project, Git will automatically add in the original url, alias called: origin.
     git remote -v: url can actually see each corresponding to an alias.
     git remote add [alias] [url]: Add a new remote repo.
     git remote rm [alias]: delete remote alias that exists.
     git remote rename [old-alias] [new-alias]: Rename.
     git remote set-url [alias] [url]: Update -push url can add and fetch without parameters, set different access addresses for the same alias.
 
2.19 git fetch
     download new branches and data from a remote repository.
     Can git fetch [alias] Take one remote repo, may be taken to all git fetch --all repo
     fetch will take you to all the data is not available locally, and take down all the branches can be called the remote branches, and their local branches, like (you can see the diff, log, etc., may also merge into other branches), but does not allow you checkout Git to them. 
 
2.20 git pull
     fetch from a remote repo and try to merge into the current branch.
     pull == fetch + merge FETCH_HEAD
     git pull executed first git fetch, then perform git merge, the head fetch branch merge into the current branch. This merge operation will create a new the commit.    
     If you use --rebase argument, it performs git rebase to replace the original git merge.
  
 
2:21 to rebase
     --rebase no merger submitted, it will be submitted to all local save for the temporary patch (patch), on the ".git / rebase" directory, then the current branch to update to the latest cutting-edge branch, and finally to save the patch is applied to the branch.
     rebase process, maybe there will be conflict, Git will let you stop rebase and resolve conflicts, after you resolve conflicts with git add to update the contents, then no need to perform commit, just:
     git rebase --continue will continue to play the rest of the patch.
     git rebase --abort will terminate rebase, the current branch will return to the state before the rebase.
 
2.22 git push
     push your new branches and data to a remote repository.
     git push [alias] [branch]
     The current branch will merge to [branch] branch on the alias. If the branch already exists, it will be updated, if not present, will be added this branch.
     If more than one person to the same remote repo push the code, Git will first try to run git log in you push the branch to check whether its history can be seen on the branch server now tip, if the local history can not be seen server's tip, that the local code is not the latest, Git will refuse you push, let you fetch, merge, and then after the push, thus ensuring all changes will be taken into account.
 
2:23 Go reflog
     git reflog is reflog management command, git reflog is a mechanism for changing a reference, such as records or changes branched HEAD reference change.
     When git reflog not specify a reference when the default list of HEAD reflog.
     HEAD @ {0} represents the current value of HEAD, HEAD @ {3} HEAD representative value before the change 3 times.
     git reflog file will change to a record corresponding to the HEAD, the path is .git / logs / HEAD, branched reflog files are placed in a subdirectory .git / logs / refs directory.
 
Special symbols:
     The representative of the parent filed, when a plurality of parent filed submitted, followed by a number in the through ^ later, represents the number of parent submitted: ^ 1 ^ equivalent.
     ~ <N> correspond to a continuous <n> a ^

reference:

  https://www.cnblogs.com/my--sunshine/p/7093412.html

  Church and school related information

Guess you like

Origin www.cnblogs.com/wjqhuaxia/p/12063689.html