Article Directory
About Git
Important and absolutely high-quality learning resources :
Liao Xuefeng’s official website: Git Tutorial
Git Pro Book
Git Official Document
Git core ideas :
- Version control (also available in SVN)
- Low-cost branch: by moving the pointer
- Local-remote distributed: do not put eggs in one basket
- Application thought: The same goal is the Git philosophy.
Modification and version rollback
For details, see git checkout/git reset/git revert/git restore. Common rollback operations.
In Git, there is a close relationship between commit, version and HEAD. Commit is the version, and HEAD is the reference to the (currently) commit. For details, see the summary of the basic concepts of the Git timeline structure related to HEAD
Checkout
Check out the current modification, here is used to eliminate the working tree changes (the working tree is the local folder)
Use format :
git checkout -- <file_name>
Note that there is a space before the file name. Only changes can be eliminated, not untracked files. Eliminate untracked files need to use clean
instructions
- If there is no stage, cancel the changes in the workspace
You can also use
git restore --worktree <filename>
orgit restore -W <filename>
- If it has been staged, cancel this stage
Reset version (reset)
Reset the HEAD pointer for version rollback.
# (对某branch)
git reset <version> <filename>`
-
The version is mostly expressed by the HEAD pointer, or the version number can be used directly
-
HEAD
Corresponding to cancel unstage, itHEAD^
is to go back one version, itHEAD~n
is to go back n versionUnstage can also use
git restore --staged <filename>
orgit restore -S <filename>
. To roll back to a specific version, you can directly add the version number. -
The default is fixed mode, and the rollback changes are returned to the working tree (unstaged changes).
Give up (restore)
Means to reset, overthrow the previous. Two types of usage of restore can be solved by checkout and reset, which are undoing work area changes and version rollback, which have been mentioned before. But for discard changes, unstage, restore syntax can be very concise:
git restore <filename>
See https://www.jianshu.com/p/dcef204dba74 for details
Revert
Means to do it again. Previous records will not be erased. Continue a specified version behind the change timeline.
Branch operations: the soul of Git
This is the most ingenious design of Git. The simple steps are as follows (see HEAD, master and branch in the figure ):
-
Create branch
-
Equal and isolated development
- Merge branch
The main grammar of addition, modification and combination
For details, please refer to the eBay tutorial to
view branches:
git branch
Create a branch:
git checkout -b <branch-name> # 创建+切换
git branch <branch-name>
Switch branches:
git checkout <branch-name>
git switch <branch-name>
git switch -c <branch-name> # 创建+切换
Merging branch:
Example : Merging branch branch1
to current branch:
git merge branch1
Conflict resolution
Two common conflicts.
The first type: manage conflicts between versions:
git diff <filename>
After using the diff command, it will appear in the original file
<<<<<<<<<<<<<<<<<<<<<<<<<<
==========================
>>>>>>>>>>>>>>>>>>>>>>>>>>
Separate the two pieces of code and manually assemble them into one.
There is also a conflict situation in remote collaboration, that is, when an empty library and a local library establish a relationship, pull
use --rebase
parameters to merge them into a compliant commit
timeline.
Remote collaboration
The remote end also has a HEAD pointer similar to the local one named FETCH_HEAD. For related issues, please refer to https://www.cnblogs.com/Venom/p/5477367.html
Associate remote library
Association method
git clone <url>
# 或
git remote add [库名]
Unlink:
git remote rm origin
The library name is origin by default. If you want to make a Gitee backup, you can delete its association with GitHub first, and then rename it to github.
Push changes (push)
The most basic sentence of remote operation: use local to change remote. It is commonly used for personal use (branch guarantee up-to-date).
grammar:
git push [主机名] [本地分支]:[远程分支]
Example scenario
-
Create a remote branch master:
git push origin master
-
Delete the remote branch master:
git push origin :master
(Push an empty branch to the specified branch origin/master)Origin represents the host name, and the push in the above two sentences corresponds to
master:master
and[null]:master
-
Create local-remote tracking:,
git push -u origin master
orgit branch --set-upstream master origin/next
-
Push updates with tracking relationship:
git push origin
(Omit the branch name, the default is the current branch and the remote corresponding branch) -
There is only one tracking branch:
git push
Usually the remote library is newer than the local one, so the push may not be completed normally, so you must first pull and then push.
Remote pull (pull)
For instructions, please refer to https://www.yiibai.com/git/git_pull.html
Fetch from remote (fetch) and import to local (merge) to deal with not-up-to-date issues.
The process is equivalent to the following three statements:
git fetch origin master:tmp
git diff tmp
git merge tmp
The sentence structure is the same as push.
If the process of creating a new warehouse is irrelevant and refuses to merge, as follows:
fatal: refusing to merge unrelated histories
Then it rebase, eliminating the process of change in ring version :
git pull --rebase origin master
Reference documents
(Please contact to delete infringement)
Liao Xuefeng's Git tutorial
Git official website documentation
git checkout/git reset/git revert/git restore Commonly used rollback operations
HEAD, master and branch
GIT undo modification restore
EasyBuy Tutorial:
git branch command
git pull command
Git fetch, git pull and FETCH_HEAD are
simple comparisons of git pull and git pull --rebase using
Git submodule to
delete untracked files (unmonitored) files in the git library
Link list
https://www.liaoxuefeng.com/wiki/896043488029600
https://git-scm.com/doc
https://blog.csdn.net/albertsh/article/details/104719370
https://www.jianshu.com/p/4219b6f62ce3
https://www.jianshu.com/p/dcef204dba74
https://www.yiibai.com/git/git_branch.html
https://www.yiibai.com/git/git_pull.html
https://www.cnblogs.com/Venom/p/5477367.html
https://www.cnblogs.com/kevingrace/p/5896706.html
http://blog.jqian.net/post/git-submodule.html
https://blog.csdn.net/ronnyjiang/article/details/53507306