Summarize your git common commands
Git also has a period of time, the use of their usual commands with their own description of the record, convenient for their own memo is also convenient for other people to refer to.
Directory:
The most basic command :
git clone copies and tracks the remote Master branch. The advantage of tracking is that you can submit or get the latest remote code directly from the pull and push commands, without having to specify a remote branch name.
Git submodule init
git submodule update
Reference
The HEAD points to the current commit object (which can be imagined as the alias of the current branch) and also indicates which branch we are working on. So when we use head to manipulate pointers, we do not change the direction of the current commit.
To understand the relationship between two submissions, the workspace (working tree), staging Area (index), and branch, compare this diagram
display Information class commands
Git ls-files-u displays conflicting files,-s is a file that is displayed as resolved by a conflict
Git diff contrasts the differences between workspace and stage files
git diff--cached Compare the difference between stage and branch
Git branch lists all branch under the current repository
Git branch--a lists all branch under local and remote
git ls-files--stage checking files saved on the stage
Git log displays all commit records to the commit that the head points to. Using the Reset head~n command to move the head pointer forward will cause the commit record after the head to not be displayed.
git log-g queries Reflog to see what actions have been recently done, so that you can work with Git branch to recover a commit object that was discarded by moving the head pointer. If Reflog is lost, you can view the commit object that is not referenced through Git fsck--full.
Git log-p-2 vs. last two commit objects
Log-1 HEAD
git log--pretty=oneline
git log--stat 1a410e view the record of a commit object SHA1 to 1a410e
git blame-l 12,22 sth.cs If you find a flaw in one of the methods in your code, you can use git blame to annotate the file, and see where each line of the method was modified by WHO. The following example uses the- l option to limit the output range to line 12th to 22nd
To create a class command
Git Brach branchname to create a branch named Branchname
git checkout branchname switch to Branchname branch
Git checkout-b Create and switch, which is the merge of the above two commands
Git brach branchname ef71 create a branchname from commit ef71 named branch
Undo Class Command
If it is a single file
1.use "git reset HEAD <file> ..." to Unstage
If you have added a file to the stage with the Add command, you need to remove it from the stage first
And then withdraw from the workspace.
2.use "Git checkout-<file> ..." to discard changes in working directory
Git checkout a.txt undo changes to A.txt (files on the workspace)
If it is multiple files
Git chenkout.
If it is already a commit, you need to
Git commit--amend To modify, this can only modify the last time, that is, with a new commit to overwrite the last commit. So if push does this again, it's going to be dangerous.
$ git reset--hard head abandons the workspace and index changes, the head pointer still points to the current commit. (Refer to the first picture)
This command can also be used to undo the not-yet-commit merge, in fact, the principle is to abandon the index and workspace changes, because no commit changes exist only in index and workspace.
$ git reset--hard head^ is used to undo the contents of the commit (equivalent to git reset--hard head~1). The principle is to discard the workspace and index changes, while the head pointer points to the previous commit object.
Git revert is also a undo command, except that reset is pointing in place or moving the pointer forward, and git revert is creating a commit to overwrite the current commit, and the pointer moves backwards
Submit Class Command
Git add keeps track of changes to new or existing files, or to resolve conflicts
Git commit commits the file from the stage to the branch
Git commit-a to submit the modified file to the stage before submitting it to branch from stash
Delete Class command
git rm--cached readme.txt only removed from the stage, preserving physical files
git rm readme.txt Not only removed from the stage, but also deleted physical files
Git MV a.txt b.txt renamed A.txt to B.txt
Merge Class command
In a conflict state, files that need to resolve conflicts are returned from index to the workspace.
1. Resolve conflicts with tools or by hand
2.git add command to indicate that the conflict has been resolved.
3. Commit the resolved conflict file again.
$ git reset--hard Orig_head is used to undo a commit merge.
$ git reset--hard HEAD is used to undo a merge that has not yet been commit, in fact the principle is to abandon index and workspace changes.
git reset--merge orig_head, notice that--hard is replaced with--merge, so you can avoid clearing working tree when rolling back.
Summarize your git common commands