Https://blog.phpgao.com/note_for_git.html
Although the concept of git is difficult to understand, but have to say that he is a development tool.
Lao Gao summed up some of the most common commands in Git, to share with you. But because of the variety of GIT commands, I will be divided into basic and advanced two parts.
I. Basics: Help
git help # get help with the following usage: git [--version] [--exec-path[=git_exec_path]] [- -html-path] [-p|--paginate|--no-pager] [ --no-replace-objects] [--bare] [-- git-dir=git_dir] [--work-tree=git_work_tree] [--help] command [args]the most commonly used git commands are: add Add file contents to the index bisect find by binary search the change that introduced a bug branch list, create, or delete branches checkout checkout a branch or paths to the working tree clone Clone a repository into a new directory commit Record changes to the repository diff show changes between commits, commit and working tree, etc fetch download objects and refs from another repository grep Print lines matching a pattern init create an empty git repository or reinitialize an existing one log Show commit logs merge &nBsp; join two or more development histories together mv move or rename a file, a directory, or a symlink pull fetch from and merge with another repository or a local branch push update remote refs along with associated objects rebase Forward-port local commits to the updated upstream head reset reset current head to the specified state rm Remove files From the working tree and from the index show show Various types of objects status show the working tree status tag create ,  LIST, DELETE OR VERIFY A TAG OBJECT SIGNED WITH GPG
Configure Git
# view configuration git config-l/--list# The following are the possible configurations core.symlinks=falsecore.autocrlf=truecolor.diff=autocolor.status= autocolor.branch=autocolor.interactive=truepack.packsizelimit=2ghelp.format=html......# Configuring global information git config--global user.name=phpgao# Configuring local Information git config--system [email protected]# View a configuration information git config user.email
Initializing the Warehouse
Git init # Initializes a git repository in the current directory git init--bare # Initializes a git bare repository in the current directory
View
Git status # shows the state of the Workflow git diff # shows the difference between the working directory (working tree) and the staging area Snapshot (index) git diff--stat # powerpoint git diff--cached # shows the text that has been staged (staged) and last commit snapshot (head) differences between Git diff--staged # The next commit will be committed to the content of the head (without the-a case) git diff dev # compare current directory and dev branch git diff HEAD # Working directory and HEAD difference git diff head^ head # compare the last and last commit different git diff dev Master # compare two branches latest commit git diff dev. Master # ibid. git diff dev ... Master # Compare all changes since the start of the branch to the git log--pretty=oneline # show log # # # beautification format one git log--pretty=format: "%h%ad | %s%d [%an] "--graph--date=short### landscaping format two git log--graph--pretty=format: '%cred%h%creset-%c (yellow)%d%creset%s%Cgreen (%CR)%creset '--abbrev-commit--date=relative
II. Additions and deletions
Read this diagram first.
650) this.width=650; "class=" Lazy img-responsive "src=" http://dl2.iteye.com/upload/attachment/0080/2435/ 75df9cfb-7c89-3c5e-bbab-1d8610a2e22d.jpg "alt=" Submission Diagram "style=" Border:0px;vertical-align:middle;height:auto;margin : 10px auto; "/>
Git add # Add workspace modified file submit to stage (index) git commit-m "comment" # submit the file in the stage (index) to the local library (commit) and add the comment git commit-am "commen T "# omitted the Add step, directly commits the content in working directory and stage (index) git rm < file name > # Delete files in the vault git reset--hard # Restores the state of the last commit, which discards the All this modified git reset--. # Recover from Staging area to working file
Iii. Branching and merging
git branch < Branch name > < Old Branch name ># create new branch based on branch git branch -r # View Remote Branch git branch -v # See the most recent commit git branch -d < branch name for each branch > # Delete a branch git br -d < branch name > # Force Delete a branch (mandatory if the branch that is not merged is deleted) git branch - m < Branch name > < New branch name > # rename a branch git checkout < branch name > # Switch to a branch git checkout -b < branch name > # Create and switch to a new branch git merge dev # Merging the current branch with the Dev branch git merge dev --no-ff # does not use Fast-foward merging, in order to maintain a clear track of the project, use this option when merging is recommended
Here the former to a concept called branching strategy, you can refer to this article Git branch management strategy.
Iv. Remote Operation clone
Git clone/xx/xxx/xxx.git # Cloning a project Git supports many protocols, such as SSH, Git, HTTPS, and so on.
Remote
Git remote-v # view remote Library git Remote add Origin xxxx.git # Add a remote host git remote RM # Delete a remote host
Fetch
GIT fetch < remote host name > # Retrieve all information git fetch < remote hostname > < branch name > # Retrieve only a branch git branch-a # view all branches git branch-r # View Remote Branch
Pull
git push
Push
V. JetBrains series software problems git remotes "Can ' t push, because no remotes is defined"
The software does not have the ability to add remote, so if you want to add a new library, you need to use the following command in terminal
Git remote Add origin "path to. Git"
Fatal:no existing author found with ' John Doe '
Use git config -l
the view configuration first to get name and email as follows
User.name=aaa
[Email protected]
Fill in the software configuration
AAA [email protected]
So the command of software conversion becomes
git commit--author= "AAA <[email protected]>"-M "Note"
Reference:
https://ruby-china.org/topics/939
git use notes