git关联本地文件夹


git关联本地文件夹

本地创建文件夹 blog 初始化git仓库

31520@DESKTOP-UV2UH9R MINGW64 /d/blog
$ git init
Initialized empty Git repository in D:/blog/.git/

获取仓库地址 关联仓库

31520@DESKTOP-UV2UH9R MINGW64 /d/blog (master)
$ git remote add origin https://gitee.com/zhangxiaocan/blog.git

将想提交到仓库的东西 复制到文件夹中

这里补充下git add的知识
将文件内容添加到索引(将修改添加到暂存区)。也就是将要提交的文件的信息添加到索引库中。

  1. git add -A 提交所有变化
  2. git add -u 提交被修改(modified)和被删除(deleted)文件,不包括新文件(new)
  3. git add . 提交新文件(new)和被修改(modified)文件,不包括被删除(deleted)文件
$ git add ./*
warning: LF will be replaced by CRLF in hexo/package.json.
The file will have its original line endings in your working directory
......

提交暂存文件

$ git commit -m '1'
git pull[master (root-commit) cd7c3f4] 1
361 files changed, 64526 insertions(+)
create mode 100644 hexo/.gitignore
......

拉取当前分支文件并合并

$ git pull
git warning: no common commits
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.

提交到远程仓库

$ git push
Enumerating objects: 355, done.
Counting objects: 100% (355/355), done.
Delta compression using up to 12 threads
......

遇到的问题

git warning: no common commits

$ git pull
git warning: no common commits
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
From https://gitee.com/zhangxiaocan/blog
* [new branch]      master     -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

原因

是因为本地分支和远程分支没有建立联系 (使用git branch -vv 可以查看本地分支和远程分支的关联关系)

解决

根据命令行提示只需要执行以下命令即可

git branch –set-upstream-to=origin/远程分支的名字 本地分支的名字

refusing to merge unrelated histories

$ git pull
fatal: refusing to merge unrelated histories

原因

因为他们是两个不同的项目,要把两个不同的项目合并,git需要添加一句代码,在git pull,这句代码是在git 2.9.2版本发生的,最新的版本需要添加–allow-unrelated-histories
假如我们的源是origin,分支是master,那么我们 需要这样写git pull origin master –allow-unrelated-histories

解决

$ git pull origin master --allow-unrelated-histories
From https://gitee.com/zhangxiaocan/blog
* branch            master     -> FETCH_HEAD

文章作者: zxc
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 zxc !
 上一篇
hexo 提交多个地址 hexo 提交多个地址
hexo配置文件 deploy: type: git repo: github: https://github.com/zxc315200728/zxc315200728.github.io gitee: https:
2020-03-05
下一篇 
CSS var() 函数 CSS var() 函数
CSS var() 函数 官方说明 定义一个名为 “–main-bg-color” 的属性,然后使用 var() 函数调用该属性: :root { --main-bg-color: coral; } #div1 { background
2020-03-02
  目录