Add
Add a new file to the index in the Git code repository
$ git add filename
Mv
Move or rename a file
$ git mv old-filename new-filename
Rm
Delete files from the working directory and the Git Code index
$ git RM filename
Status
View the current working directory's code status, additions, modifications, and deletions since the last commit
$ git status
Diff
View the specifics of local code churn since the last commit
$ git diff
Commit
Commit the modified code (just submit to the local code base and not push to the server)
$ git commit-am ' modify description '
If you feel that the "modification notes" you just submitted are not well written, you can enter the following command to adjust
$ git commit--amend
Push
Pushes a local commit, since the last push, to the server
In combination with our reality, it should be written like this:
$ GIT push origin Master:your-id
Where master is the local branch name, Your-id fills in your ID on the server, and the server's repository has a branch with the name of your ID.
Pull
Code that pushes someone else to the server and pulls it into your machine
$ git pull
Log
Review the changes, including the author, time, modification instructions, etc.
$ git log
Show
Show specific code Churn
Displays the contents of the last commit modification:
$ git Show
Displays the contents of the specified commit modification:
The "TIP" git log command, each commit will have a long string, this is the Commid ID, take its front five or six bits.
$ git show Commit-id
Branch
Branch Management
List all branches (there will be "*" numbers before the current branch):
$ git Branch
New branch:
$ git Branch New branch name
To delete a branch:
$ git branch-d The name of the branch you want to delete
Note "Don't put '-d ' as a '-d ', Dangerous!"
- -D: Requirements: All modifications to the deleted branch have been merged into the current branch;
- -D: Delete directly, not merged code, will be discarded!
Checkout Recover a modified file (undo uncommitted changes):
$ git checkout file-name
Switch to a different branch for development:
$ git checkout branch-name
Note "This command may accompany a large number of file additions/deletions/modifications. Under Windows, changes to the files that are already in use may be rejected, causing serious problems with the repository. If you do this, it's a good idea to log off once, for security reasons.
Merge
Merges the specified branch to the current branch:
$ git Merge Branch-name
Revert
Revert submitted changes (changes that have been submitted, can be undone ~)
Revert the last-commit modification:
$ git revert HEAD
To revert the modification of the specified version:
$ git revert Commit-id
Stash
The uncommitted changes are staged first, and then all changes are cleared to be the same as if they were not modified.
If you are developing feature A, you need to develop feature B immediately. A's code is changing to half, not carefully organized, you do not want to submit immediately. At this time ... Please call stash ~.
It will make all of your uncommitted changes disappear instantly:
$ git stash
It would make the changes that had just disappeared, and instantly came back again:
$ git stash pop
The "TIP" commands above have more parameters, and some Git commands are not covered here. However, this is enough to make you use Git, you will feel, Git is an artifact! :-)
"TIP" ' $ git help ' and ' $ git helper command name ' will be selflessly helping you when you need it. :-)
Attached: git push failed solution
Assume that the action is performed:
1. Modify Code 2. Git commit 3. git push
Push failed at this time (Error:!) [Rejected] master, Master (Non-fast-forward))
Workaround:
$ git pull
If successful, then:
$ GIT push origin Master:your-id
Done.
If it fails (hint: CONFLICT (content): Merge CONFLICT in File name), then:
Conflicting files will have code blocks similar to the following:
<<<The code you modified
============
Code modified by someone else
>>>>>commit ID of others '
Consider the changes you and others have made to the code, update to the appropriate content, and delete the <<<, = = =, >>> 3 line marker symbols to save the file.
$ git commit-am "resolve conflict" $ GIT push origin Master:your-id
For a more detailed explanation, you can read the note about Fast-forwards section of the document that $git Push–help.
About Git's stash