[Recommended collection] Share some commonly used Git commands in work and how to solve special problem scenarios

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 initNeedless to say, we all know that this command is to initialize the current directory becomes possible to use gitmanagement of warehouses and empty.

git init

git clone remote address [url]

It is git clonedownloaded from a remote address through a command, and this does not need to be described too much.

git clone

git status

git statusCheck how many local files have changed this time. You can see index.cssd and index.htmlchanges

git status

git log

git logView the logs currently submitted.

git log

git diff

git diffIt is to check the specific code content of the currently changed file.

git diff

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.cssonly restore the current modification of this file.

git checkout

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 add

git commit -m "Your comment to be submitted"

git commit -mThe content here is written from the temporary storage area to the object library. Note that the comments must be written .

git commit

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 show tag

git push origin tagName (your tag name)

git push origin v1.0Push to remote

git push origin branch (your branch)

git push origin branchPush to the remote warehouse.

git push origin branch

git pull origin branch (your branch)

git pull origin branchPull from remote to local.

git pull origin branch

git checkout branch (your branch)

git checkout branchSwitch to another branch.

git checkout branch

git checkout -b branch (your branch)

git checkout -b branch(分支名称)Create a new branch and switch to that branch.

git checkout -b

git branch -v

git branch -vView the current branch with the last commit information behind

git branch -v

git branch -a

git branch -aView all current branches including remote branches

git branch -a

git branch branch (your branch)

git branch barnch(你的分支名称)Create a new local branch.

git 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 -vView source address

git remote -v

git remove remote name (source address name)

git remove remote nameDelete the source address.

git remove remote name

git remote add name (source address name) remote address [url]

git remote add name urlAdd a source address as the address of the warehouse to be submitted.

git remote add name

git fetch origin name (remote branch name)

git fetch origin nameIf 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 fetch

git merge name (the name of the branch to be merged)

git merge name(要合并的分支名称)Merge the branch to be merged into other branches. The testcode on the branch into developthe.

go merge

How to solve special problem scenarios

I just want to merge a commit to other branches

For example, a scene developbranch has some special code, so the code on this branch cannot be merged into the testbranch. We only want to merge the currently modified code. What to do git cherry-pickis to solve this problem. Let’s take a look at the following example.

git cherry-pick

In the above example, this is git cherry-pickfollowed 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 belowididididgit loggit add .git cherry-pick --continuegit 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 "重新提交注释"

git commit --amend

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~1Withdraw the comment just now, if you submit it twice, committhen withdraw it twice git reset HEAD~2.

git reset HEAD~1

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

Guess you like

Origin blog.csdn.net/weixin_44165167/article/details/114252114