This content reference: http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
Beginner, what's wrong with the place, welcome to point out
First, the workspace (local warehouse)
1. Create warehouse (repository): Git init
Usage: Execute git init in folder (folder into warehouse) directory
2. Add File: Git add [File path]
Such as:
Commit file: Git add test.txt Commit folder: Git add Test commits any file: Git add * commits all files in the current directory: Git Add. Add all files and delete deleted files from the repository: Git add-u 3, delete files:
1) RM [File path] or delete files directly in File Manager such as: RM text.txt Note: Recover files git checkout rext.txt 2) Delete and delete versions in warehouse git RM [File path] Note: 1)) Recover files: Git rest HEAD [File Road ]2) git checkout [File path] 4, fallback version: Git rest hard commit_id such as: Git rest--hard 12345
git reset
The command can be rolled back to the version, or the staging area's modifications can be rolled back to the workspace. When we use
HEAD
, the latest version is indicated. With the command
git reset HEAD file
You can undo the staging area changes (Unstage), back to the workspace 5, get the most information: git log Note: You can rollback the version based on the ID of the returned log, such as: Git rest--hard 12345 6, view command history: Git reflog 7, Get Warehouse status information (add, delete, change file related information): Git status 8, undo modify (Discard workspace changes) git checkout--[file]
注:git checkout -- file
In the command
--
It's important, No.
--
, it becomes the "Create a new branch" Command II, remote Warehouse 1, create SSH Key1) in the user home directory, see if there is no. ssh directory, if there is, then look at this directory there is no
id_rsa
And
id_rsa.pub
These two files, if you already have one, can jump to the next step directly. If not, open the shell (open git Bash under Windows), create an SSH key, the password is optional, enter the following command: Ssh-keygen-t rsa-c "[email protected]" Finally give your public key to Git Manager 2, Run command under associated remote Repository repository: Git remote add origin [git address] such as: Git remote add origin [email protected]:michaelliao/learngit.git 3, The contents of the local library are pushed to remote: Git push-u origin [file] such as: Git push-u origin master-u: Because the remote library is empty, the first push
master
Branch, the Local
master
Branch content pushes the remote new
master
Branch, it will also bring the local
master
Branch and remote
master
After the branch is associated, the connection is pushed to the remote can add-u parameter 4, clone remote Library to Local: Git clone [git address] such as: Git clone [email protected]:michaelliao/ Gitskills.gitgit supports a variety of protocols, including
https
, but through
ssh
Support for native
git
The speed of the protocol is the fastest. &NBSP;5, Branch (branch) 1) Create a branch: Git branch [branch name] such as: Git branch dev 2) switch branch: git checkout [branch name] such as: Git checkout dev 3) Create and switch branches: git checkout-b [branch name] such as: Git Check-b dev actually executes 1) and 2) two commands 4) View branch: Git branch note: Git branch command lists all branches, current Branches preceded by a * number 5) Merge branches to the current branch: git merge [branch name] such as: git merge dev 6) Delete branch: git branch-d [branch name] such as: Git branch-d de V&NBSP;6, conflict resolution <<<<<<< head (head points to the current branch at the distal point of the commit. Creating a new branch is quick & simple. (The contents of the current branch.) ) ======= Creating A new branch is quick and simple. (The code on the other branch that the merge came over.) ) >>>>>>> Feature1 (name of the branch) &NBSP;7, Branch Management policy 1) Fast forward mode (default): In this mode, when the branch is deleted, the branch information is discarded. The merger would not have been seen as a merger. 2) Normal mode (--no-ff parameter): Normal mode merging, merging history has branches, can see that once did merge. For example: git merge--no-ff dev (using normal mode) 8, save/Restore workspace 1) storage: git stash2) Restore: 2-1) View storage information: Git stash list2-2) recovery: 2-2-1) git Stash apply: After recovery, stash content is not deleted, need to use git stash drop to delete; 2-2-2) git stash pop: Restore stash content also deleted: usage: git stash apply [stash_id]/ git stash pop [stash_id] such as: git stash apply [email protected]{0} 9, discard a branch that has not been merged (forcibly deleted): git branch-d [branch name] such as: git branch-d dev Note: No merged branches, need to forcibly delete to delete 10, view remote Library information: git Remote-v: View details Note: Without push permissions, you cannot see the address of the push 11, push branch: Git push origin [branch name] 12, pull branch: Git pulls Origin [branch name] &NBSP;13, establishing local branch and Remote Branch Association: GIT Branch--set-upstream [work Distinguished branch name] origin/[Server branch name] such as: Git branch--set-upstream Dev origin/dev& NBSP;14, ignore file Create a special in the root directory of the Git workspace
.gitignore
files, and then fill in the file names you want to ignore, and git will automatically ignore them. Add version control to ignore files you can also use the command: git add [file]-F
Common command operations for getting started with Git basics