Preface
Original intention: I remember that when I first entered the industry, the Git tool made it difficult to understand that there was always a code conflict, and it was even out of sync with the code of my colleagues (it was difficult to think about it at that time). Recently, I sorted out the Git note commands and shared them with you to avoid mistakes.
Suitable for the crowd: the front-end primary development, the big guys detour.
Content structure: common basic operation commands -> how to solve special problem scenarios.
Commonly used basic operations
git init
This git init
Needless to say, we all know that this command is to initialize the current directory becomes possible to use git
management of warehouses and empty.
git clone remote address [url]
It is git clone
downloaded from a remote address through a command, and this does not need to be described too much.
git status
git status
Check how many local files have changed this time. You can see index.css
d and index.html
changes
git log
git log
View the logs currently submitted.
git diff
git diff
It is to check the specific code content of the currently changed file.
git checkout .
git checkout .
That is, all the changed ones are restored to their original appearance, of course, the specified ones can also be restored, such as: git checkout index.css
only restore the current modification of this file.
git add .
git add .
It is to add the modified content to the temporary storage area, and you can also submit the specified file.
git commit -m "Your comment to be submitted"
git commit -m
The content here is written from the temporary storage area to the object library. Note that the comments must be written .
git tag
View the current tag tag
git tag tagName (your tag name)
Create a new tag
git tag -a tagName -m "tag remarks"
Create a new tag label with remarks information
git show tagName (your tag tag name)
View current tag remarks information
git push origin tagName (your tag name)
git push origin v1.0
Push to remote
git push origin branch (your branch)
git push origin branch
Push to the remote warehouse.
git pull origin branch (your branch)
git pull origin branch
Pull from remote to local.
git checkout branch (your branch)
git checkout branch
Switch to another branch.
git checkout -b branch (your branch)
git checkout -b branch(分支名称)
Create a new branch and switch to that branch.
git branch -v
git branch -v
View the current branch with the last commit information behind
git branch -a
git branch -a
View all current branches including remote branches
git branch branch (your branch)
git branch barnch(你的分支名称)
Create a new local branch.
git branch -D name (branch name)
git branch -D name(分支名)
Delete the local branch, but you cannot delete the current branch on the current branch. You must switch to another branch and delete other branches.
git remote -v
git remote -v
View source address
git remove remote name (source address name)
git remove remote name
Delete the source address.
git remote add name (source address name) remote address [url]
git remote add name url
Add a source address as the address of the warehouse to be submitted.
git fetch origin name (remote branch name)
git fetch origin name
If we don't have this branch locally but have this branch remotely, we first pull down the remote branch and create a new local branch and associate it with the remote branch.
git merge name (the name of the branch to be merged)
git merge name(要合并的分支名称)
Merge the branch to be merged into other branches. The test
code on the branch into develop
the.
How to solve special problem scenarios
I just want to merge a commit to other branches
For example, a scene develop
branch has some special code, so the code on this branch cannot be merged into the test
branch. We only want to merge the currently modified code. What to do git cherry-pick
is to solve this problem. Let’s take a look at the following example.
In the above example, this is git cherry-pick
followed by another branch commit record . To view this , I mentioned the use of viewing logs. There is no conflict in my case code, so if some small partners have a conflict, first resolve the conflict and then continue to execute the current process in this parameter . Let's see a few parameters belowid
id
id
id
git log
git add .
git cherry-pick --continue
git cherry-pick
--continue
After the user resolves the code conflict, the first step is to re-add the modified file to the temporary storage area (git add .), and the second step is to use the following command to let the Cherry pick process continue.--abort
After a code conflict occurs, give up the merge and return to the way it was before the operation.--quit
After a code conflict occurs, quit Cherry pick, but it does not return to the way it was before the operation
What should I do if the comment is wrong when I commit?
git commit --amend -m "重新提交注释"
Remote force coverage to local
$ git fetch --all(下载远程库的所有内容)
$ git reset --hard origin/master(远程的分支名称)
$ git pull
How to withdraw after commit is submitted
git reset HEAD~1
Withdraw the comment just now, if you submit it twice, commit
then withdraw it twice git reset HEAD~2
.
Git develops the wrong branch
When the code is not submitted
git add .
git stash (把暂存区的代码放入到git暂存栈)
git checkout name(切换到正确的分支)
git stash pop(把git暂存栈的代码放出来)
After submitting the code
git reset HEAD~1 (最近一次提交放回暂存区, 并取消此次提交)
git stash (暂存区的代码放入到git暂存栈)
git checkout (应该提交代码的分支)
git stash pop (把git暂存栈的代码放出来)
git checkout (切换到刚才提交错的分支上)
git push origin 错误的分支 -f (把文件回退掉)
thank
Thank you for opening this article during your busy schedule. I hope it will be helpful to you. If you have any questions, you are welcome to correct me.
If you think it's okay, just give it a thumbs-up for it. ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
Are interested, you can also add my personal vx exchange Click here