Git传代码到Gitee(解决问题:fatal: refusing to merge unrelated histories)

  • 生成ssh公钥
  1. 安装好git软件
  2. 右击鼠标 git bash here。在命令栏里输入命令:ssh-keygen -t rsa -C "码云绑定的邮箱"
  3. 三次回车(其中后两次是输入密码和确认密码);然后打开id_rsa.pub文件添加到个人安全公钥。即可。
  •  上传文件到远程仓库
  1. 创建文件
  2. 创建本地仓库
  3. 添加文件到寄存区
  4. 连接远程仓库
  5. 将远程仓库的分支与本地分支合并
  6. 提交
jdq8576@LAPTOP-LKV16HOT MINGW64 ~/Desktop/test
$ vim jdq.txt

jdq8576@LAPTOP-LKV16HOT MINGW64 ~/Desktop/test
$ git add jdq.txt
fatal: Not a git repository (or any of the parent directories): .git

jdq8576@LAPTOP-LKV16HOT MINGW64 ~/Desktop/test
$ git init
Initialized empty Git repository in C:/Users/jdq8576/Desktop/test/.git/

jdq8576@LAPTOP-LKV16HOT MINGW64 ~/Desktop/test (master)
$ git add jdq.txt

jdq8576@LAPTOP-LKV16HOT MINGW64 ~/Desktop/test (master)
$ git remote add origin https://gitee.com/jdq8576/test.git

jdq8576@LAPTOP-LKV16HOT MINGW64 ~/Desktop/test (master)
$ git commot -m "123"
git: 'commot' is not a git command. See 'git --help'.

The most similar command is
        commit

jdq8576@LAPTOP-LKV16HOT MINGW64 ~/Desktop/test (master)
$ git commit -m "123"
[master (root-commit) 3b22d14] 123
 1 file changed, 1 insertion(+)
 create mode 100644 jdq.txt

jdq8576@LAPTOP-LKV16HOT MINGW64 ~/Desktop/test (master)
$ git pull origin master --allow-unrelated-histories
warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://gitee.com/jdq8576/test
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
Merge made by the 'recursive' strategy.
 README.md | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 README.md

jdq8576@LAPTOP-LKV16HOT MINGW64 ~/Desktop/test (master)
$ git push origin master
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 512 bytes | 73.00 KiB/s, done.
Total 5 (delta 0), reused 0 (delta 0)
remote: Powered by Gitee.com
To https://gitee.com/jdq8576/test.git
   a902582..cf3660c  master -> master

猜你喜欢

转载自blog.csdn.net/jdq8576/article/details/83148673