Git Version Control Notes

1. About Git

        Official introduction: Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git is an open source distributed version control system that can handle everything from small to very large projects effectively and at high speed Very large project version management.

        Creator: Linus Torvalds.

        Motivation for creating Git: Better management of the Linux kernel.

2. Notes on Git version control (common commands)

        1. Configure the identity information of the submitter (you can let others know who submitted the code)

git config --global user.name "your name (written by you)"
git config --global user.email "your email (written by you)"

        2. Check your identity information

git config --global user.name
git config --global user.email

        3. Create a local code repository for the xxx project

第一步:进入xxx项目路径

第二步:在该路径下输入git init

第三步:查看仓库是否创建完成,可以通过ls -al命令查看是否有.git目录,有就是创建成功了

        4. Delete the local code warehouse of the xxx project

直接在xxx路径下删除.git目录

        5. Add the xxx project code to be submitted soon

第一种(单文件方式):git add 文件名

第二种(全部文件方式):git add .

第三种(全部文件方式但部分文件或路径不想提交):在xxx项目下添加.gitignore文件,该文件中加入不想提交的文件或路径,然后执行git add .

        6. Formal submission (descriptive information must be filled in)

git commit -m "提交的描述信息"

        7. Check the submission record

查看全部提交记录:git log

查看单个提交记录:git log 记录id

查看最新n次提交记录:git log -n

        8. Check the contents of the modified file after commit (do not check it as soon as you commit, it will be undetectable; the modified file after commit is valid only by calling the following two commands)

文件层面:git status

文件内容层面:git diff

具体文件(假设是"a.java"这个文件)内容层面:git diff a.java

        9. Undo uncommitted modifications (only applicable to files that have not been executed by the add command)

git checkout 文件名

        10. Undo the uncommitted modification (mandatory undo) (I don't know what the "HEAD" means, please let me know if you understand)

git reset HEAD 文件名

        11. Create a branch

git branch 分支名

        12. Switch to the branch v1 (assuming the branch v1 has been created)

git checkout v1

        13. If this error occurs when switching branches (for example, executing git checkout master): Your local changes to the following files would be overwritten by checkout Please commit your changes or stash them before you switch branches, please refer to this blog .

        14. Merge branches

第一步:切换回master,执行git checkout master

第二步:执行git merge v1(假设分支v1存在)

        15. Delete branch

git branch -D v1(假设分支v1存在)

        16. Collaborate with remote version warehouses

假设https://github.com/example/xxx.git是远程版本仓库

下载仓库到本地:git clone https://github.com/example/xxx.git

本地上进行了修改和提交,同步到这份远程版本仓库:git push origin master(origin部分指远程版本仓库地址,master部分指同步到哪个分支)

远程版本仓库的修改同步到本地(第一种方式):
1.git fetch origin master(同步下来的代码不会合并到任何分支上,而是会存放到origin/master分支)
2.通过diff查看远程版本仓库修改内容:git diff origin/master
3.调用merge命令将origin/master分支的修改合并到主分支:git merge origin/master

远程版本仓库的修改同步到本地(第二种方式):
git pull origin master(pull命令≈fetch命令+merge命令)


3. References

        1、Git

        2. Distributed version control system

        3. Guo Lin, the first line of code Android version 3

Guess you like

Origin blog.csdn.net/qq_36158230/article/details/131794512
Recommended