1. New warehouse
git init
After initializing the repository, you can find an additional.git directory in the current directorygit remote add origin [email protected]:joel/test.git
The local repository is associated with the remote repository. Origin is the default name and can be changedgit push -u origin master
Push all content from the local library to the remote library. Since the remote library is empty, the first time we push the master branch, we add it-u
Parameters (push and association), subsequent push can simplify instructions.
Two, commonly used modification instructions
git add xxx.txt
Add, but do not commit,git add.
Add all files.Git commit -m
Submit, only after add submission is valid.
Three, common view instructions
-
Git status Displays the current status of the repository
-
Git diff: git diff
-
Git diff version 1 Version 2 –stat Displays a list of files that are different between two versions, including the number of lines changed and the chart of additions and deletions. If the parameter is changed to –name-status, the modification description letter (A,M, etc.) is displayed before the parameter, and the number of lines is not displayed
-
Git branch Displays the current branch. The git branch command lists all branches, with the current branch preceded by an asterisk
-
Git log displays commit logs from the most recent to the most distant
-
Git remote Displays information about the remote repository
4. Undo modifications and version rollback
Git checkout -- file name
Kill those without staging (i.e., no Add), or discard the workspace and return to stagingGit reset HEAD File name
Cancel the temporary state, workspace contents remain unchanged, but the state changes to “not temporary”.
Git checkout — git checkout — git checkout — git checkout — git checkout Git checkout — git checkout — git checkout — git checkout
git reset --hard HEAD^
Will fall back to the previous versionGit reset --hard the first few digits of a version number
Rollback to the specified version
5. Branch management
-
Git branch dev creates a pointer to the current commit
-
Git checkout dev switches to the dev branch
-
Git checkout -b dev creates a new branch dev and switches to the dev branch. This is equivalent to two commands: git branch dev and git checkout dev
-
Git merge dev git merge dev git merge dev
-
Git branch -d dev Deletes the merged branch.
-
Git rebase master. If this command is executed in the current branch (non-master), the current branch is merged with the mater branch. This operation is similar to merge but has a different commit history.