写在前面:
origin分支:
当我们在使用git clone的时候,git会自动地将这个远程的repo命名为origin,拉取它所有的数据之后,创建一个指向它master的指针,命名为origin/master,之后会在本地创建一个指向同样位置的指针,命名为master,和远程的master作为区分。
也就是说,origin的含义指的是远程的仓库。它只是一个标记,就和默认分支叫做master一样,本身并没有特别的含义。
代码拉取:
git pull并不是严格意义上的代码拉取命令, 实际上git fetch才是真正的代码拉取的操作,它的作用是将远程的改动同步到本地。 这两者从表面上来看都是拉取远程的改动。但是两者针对的范围不同,git fetch针对远程的所有改动,而git pull只针对当前分支对应的远程分支 。另外git pull执行之后会将远程的改动merge到本地的分支,也就是说它其实多了一步merge的操作。
参考链接:https://blog.csdn.net/TechFlow/article/details/109352820
Git clone 是一个用于从远程仓库克隆项目的命令。
mkdir->cd->init->remote-add->pull 是一种手动搭建 Git 仓库的方法,适用于本地创建新项目并与远程仓库关联的场景。
- 标签是静态的,一旦标签打好后,其中的文件就定格了。(举例:框架的版本发布)
- 分支是动态的,其中的文件状态可以发生改变。
vscode + git:
1.基本操作
命令行:git status:
可以查看在你上次提交之后是否有对文件进行再次修改。
git status 命令会显示以下信息:
当前分支的名称。
当前分支与远程分支的关系(例如,是否是最新的)。
未暂存的修改:显示已修改但尚未使用 git add 添加到暂存区的文件列表。
未跟踪的文件:显示尚未纳入版本控制的新文件列表。
vscode:文件右侧加号:stage Changes == 命令行 git add

文件由工作区添加到暂存区
减号:文件由暂存区添加到工作区
vscode:commit +"message" == git commit -m 'message'


git pull拉代码
git push
vscode:checkout切换分支


git fetch更新远程仓库的代码为最新的,本地仓库的代码还未被更新
远程仓库可以用git remote -v查看(这里的远程仓库是保存在本地的远程仓库,等同于另一个版本,不是远程的远程仓库)
git merge选择一个分支与其同步

**git checkout -b (branchname) :**创建新分支并立即切换到该分支下,从而在该分支中操作。

2.版本管理
1.git graph插件
可以看到commit的详细信息

123依次是拷贝文件的绝对路径,当前commit的这个文件内容,最新commit的文件内容。

点击文件显示和父commit的对比:

空心小蓝点:现在在哪个commit上

切换commit : git checkout (commit)

粉色代表remote branches

橙色是tag

对比当前commit和很久之前的commit的区别:先找一个,点击,再找另一个,CTRL 点击。
2.git history插件
可以查看所有commit的history,对于某一个文件的所有commit的history,文件中某一行所有的commit记录(某一行代码出现重大的bug看看是谁改的)。
搜索只能搜message信息,分支只能选本地分支
对比当前commit和很久之前的commit的区别:more->select this commit. more->compare with

按钮soft hard == 命令行 git reset --mixed 为默认,可以不用带该参数,用于重置暂存区的文件与上一次的提交(commit)保持一致,工作区文件内容保持不变。
--soft 参数用于回退到某个版本:
git reset --soft HEAD~3 # 回退上上上一个版本
--hard 参数撤销工作区中所有未提交的修改内容,将暂存区与工作区都回到上一次版本,并删除之前的所有信息提交:
git reset --hard HEAD