git daily notes (updated from time to time)

git command:

1. Submit the specified branch code with git: git push --set-upstream origin 指定的分支名
2. Create a new branch and switch to the new branch: git checkout -b 分支名
3. View the current branch: git branch
4. Switch branches (existing branches): git checkout 分支名
5. Delete branches: git branch -d 分支名
6. Pull the latest content of the branch: git pull
7. Copy this branch Merge branch content into the develop branch: git merge develop
8. Discard all locally edited content of the current branch: git reset --hard origin/当前分支名
9. When submitting:

	git add .
	git commit -m "描述提交的内容"
	git push

10. Clear cache:git cache clean -f

git rollback version:

The first step is to check the version number git log
. The second step is to find the version number that you need to roll back and copy the version number.
The third step is to do the reverse of 1) and enter the command " git revert -n 回退的版本号". (Note: There may be conflicts here, so you need to manually modify the conflicting files). And want to git add 文件名.
2) Submit, use " git commit -m 版本名", such as: git commit -m "revert add text.txt"At this time, you can use " git log" to view the local version information. It can be seen that a new version has been generated locally.
3) Use " git push" to push the remote library, successfully.

After git commit, if the commit is revoked:
After executing the commit, but before the push is executed, if you want to revoke this commit, you can use the command: git reset --soft HEAD^(In this way, the commit can be successfully revoked, 如果想要连着add也撤销的话,将 --soft 改为 --hardwhich means deleting the modified code of the workspace).
Detailed explanation of the command: HEAD^ represents the previous version, that is, the last commit, which can also be written as HEAD~1. If you make two commits and want to withdraw them both, you can use HEAD~2.
--soft 不删除工作空间的改动代码,撤销commit,不撤销 git add file.
--hard 删除工作空间的改动代码,撤销commit 且撤销add.
In addition, if the commit comment is written incorrectly, you need to change the comment first. There are other methods to achieve this. For example, you git commit --amendwill enter the vim editor at this time, modify the comment you want, and then save it.

Other commands will be added later. If there are any mistakes, please correct me friends! Thanks

Guess you like

Origin blog.csdn.net/panpan_Yang/article/details/113843536