1. After the git installation is complete, first use the
" Your Name " "[email protected]"
Set up personal information
2. Create a repository with the git init command in a directory that can be created from an empty directory or created in an existing project.
3. The git add command can add files to the Git repository. You need to add a file after each modification. The essence of this step is to submit the document to staging area.
4. Git commit is used to submit files to the repository after the file has been modified, usually in the format
" Comments "
The comments in parentheses is the added comment.
The essence of this step is to submit the staging area file to the current branch, without the add modification being committed.
5. Git status can view the current status.
For files that have been modified and have been add, Git displays
Changes to be committed:
(use "Git reset HEAD <file> ..." to Unstage)
For files with no add, Git displays
Changes not staged for commit:
(use "git add <file> ..." To update what would be committed)
(use "Git checkout--<file> ..." to discard changes in working directory)
6. Git diff is used to see the difference between a file that does not have an add and the file that has been added (including a file that has already been commit)
7. Git log can view the history of commit, which is submitted after the above.
8.
git reset--hard head^
The command can be returned to the previous version. Where head^ represents the latest version of the previous version, head is the latest version.
git reset--hard Commitid
You can return to the version of the specified commit ID, which is viewed in Git status and only needs to be entered in the first few. This command can be moved forward or backward.
9. Git reflog can view every command executed, and the ID will also be displayed.
Git checkout-file can undo the last modification of the workspace after git add or git commit. Note--There are spaces after that.
Git reset HEAD file can undo changes to the staging area (already add) and back to the workspace
12. After deleting a file, if you want to delete it from Git, git rm and git commit will be required, if you want to revert to git checkout-file
13. Before using remote git, you need to create an SSH key locally and command
Ssh-keygen " [email protected] "
A. SSH directory is created with the private key id_rsa and the public key id_rsa.pub, where the private key is not compromised. To use on GitHub, you need to first add the public key to the GitHub SSH key list.
14. By
git remote add origin [email protected]:netaddi/learngit.git
Or
Git remote add origin https://github.com/netaddi/learngit.git
Associates the remote library locally, where origin is the local name of the remote library.
15. After the association, by
Git push-u Origin Master
command to push the current branch master to the remote repository,-u indicates that the local master branch and the remote Master branch are associated. After that, the remote push does not need to add the-u parameter.
16. Cloning from a remote repository:
git clone [email protected]:netaddi/learngit.git
Or
git clone https://github.com/netaddi/learngit.git
17. Create and switch a new branch:
Git branch branchname create a new branch
git checkout branchname switch to new branch
Git checkout-b branchname
This command corresponds to two of the above.
Git branch can view the current branch.
After switching, the current branch can be submitted normally. If you switch to another branch, the content you edited on the previous branch is not visible.
To merge two branches, use the git merge branchname command.
The default merge is Fast forward mode, which discards historical information and discards historical information when the branch is deleted. If you use--NO-FF, you can disable the FF mode, and a new commit will be generated when you merge, and you can see the branching information from the branch history.
git branch-d branchname Delete a branch
When encountering a conflict, you need to resolve the conflict manually before committing.
git log--graph can view the branch as a graph.
The git stash command can store the current branch and return to the environment after commit.
When you need to recover, git stash List command can see what stash, git stash apply can recover, drop delete, pop recover and delete.
Git remote allows you to view information about the repository, adding the-v parameter to see more detailed information.
Git Learning Notes