常用命令

拉取本仓库远程分支到本地

  • git fetch origin 分支名

  • git checkout 分支名 // 拉取到本地但是不切换分支

  • git checkout -b dev(本地分支名称) origin/dev(远程分支名称) // 将远程分支拉取到本地并切换分支

Configuring a remote for a fork

  • 给 fork 配置一个 remote

  • 主要使用 git remote -v 查看远程状态。

git remote -v
# origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
# origin  https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
  • 添加一个将被同步给 fork 远程的上游仓库

git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
  • 再次查看状态确认是否配置成功。

git remote -v
# origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
# origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
# upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
# upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)

Syncing a fork

  • 从上游仓库 fetch 分支和提交点,传送到本地,并会被存储在一个本地分支 upstream/master

    git fetch upstream

  • 切换到本地主分支(如果不在的话)

    git checkout master

  • 把 upstream/master 分支合并到本地 master 上,这样就完成了同步,并且不会丢掉本地修改的内容。

    git merge upstream/master

  • 如果想更新到 GitHub 的 fork 上,直接 git push origin master 就好了。

现有的文件夹或Git版本库

git回滚到之前提交的某个版本

参考:https://blog.csdn.net/tsq292978891/article/details/78965693arrow-up-right 先显示提交的记录:

回到指定版本:

强制提交:

git修改commit备注信息

git commit --amend 此时会进入默认vim编辑器,修改注释完毕后保存就好了。

reference

git使用情景2:commit之后,想撤销commitarrow-up-right

最后更新于