vscode_git

Git

  1. clone : 所有版本有一个远程仓库,把它复制到本地工作区称为 clone

  2. add: 增加的内容载入暂存区。

  3. commit: 为添加的到副本的内容起一个名字,最终将添加的内容加入本地仓库。

  4. push: 把本地仓库里新增的添加到正本里面

  5. pull:其他成员把远程仓库同步更新到自己的工作区,注意会覆盖本地文件。

  6. fetch: 将远程仓库更新的本地版本仓库。

  7. diff: 对比区别,没问题在合并过来。

  8. 文件的几个状态:

    • untracked: 新建的文件
    • upstage: 被 track 且被修改的文件
    • stage: 已经被 track

实操

  1. git init 初始化。
  2. git status 查看当前文件的状态。
  3. git add 将修改暂存到缓存区。
  4. git commit -m 输入提交信息。
  5. git status nothing to commit,也就是把所有文件都提交到本地版本库了
  6. git log 查看记录,谁提交的
  7. touch .gitignore.gitignore 增加忽略的文件名即可。
  8. git commit -am 信息 将 add 和 commit 合并在一起写。

分支

不确定当前修改是否需要,可以创建新的分支,在新分支里修改,准备好后可合并到主分支中。

  1. git branch 查看分支,+ 分支名 创建分支。
  2. git checkout + 分支名 切换分支
  3. 注意: 如果在分支里删除.ignore 文件, 在主分支里也会被删除
  4. git branch -d : 删除分支
  5. git checkout -b 创建并切换到新分支。
  6. git merge + 分支名 把其他分支合并到所在分支。注意冲突

上手 Github

  1. git-clone + http 连接 github上一开始创建时的主支名字是 main 而本地用git 则是 master.
  2. git remote -v 查看本地仓库和哪些远程仓库有联系。默认用 origin 代表远程仓库的名字。
  3. git remote add 自己选名字 <url>/git remote remove 添加远程仓库连接。
  4. 生成 token
  5. git fetch 可以指定远程仓库和分支名的。
  6. git diff 远程仓库名/分支名 看到区别。

问题汇总

在git中走代理

1
2
3
4
5
6
7
# 设置
git config --global http.proxy 'socks5://127.0.0.1:7890'
git config --global https.proxy 'socks5://127.0.0.1:7890'

# 恢复
git config --global --unset http.proxy
git config --global --unset https.proxy

curl -v https://www.google.com 查看是否成功

很多网络的原理都不清楚,打算以后来补。

Git Upstream Branch

"Upstream Branch" is the remote branch hosted on Github. It’s the branch you fetch/pull from whenever you issue a plain git fetch/git pull basically without arguments.

git push --set-upstream origin <branch name> 来设置.

How to set up Upstream Branch on Git

refusing to merge unrelated histories

一般出现在创建新仓库的时候新建 readme.md文件,然后在pull 的时候,所以最后的流程最好是先在远程仓库建好,然后 clone. 解决方法强制合并

1
git pull origin branchname --allow-unrelated-histories