Git——使用git clone工程,或者进行代码管理时遇到的一些问题

文章参考:https://www.centos.bz/2018/03/git-%E5%87%BA%E7%8E%B0-fatal-refusing-to-merge-unrelated-histories-%E9%94%99%E8%AF%AF/https://blog.csdn.net/huanhuaqian/article/details/81986064


使用git时遇到的问题及解决方法。

将代码上传到github时的步骤:
1.在本地建一个仓库,使用init命令。
nn@PARIS MINGW64 /d/workspace/flutter_app_demo01
$ git init
Initialized empty Git repository in D:/workspace/flutter_app_demo01/.git/
2.在github上建一个仓库。
3.将两个仓库关联。
4.拉取或提交代码都可以。

------------------------------------------------------------------------

问题:执行commit时无法确定身份。
nn@PARIS MINGW64 /d/workspace/flutter_app_demo01 (master)
$ git commit -m "first commit"

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

解决:
nn@PARIS MINGW64 /d/workspace/flutter_app_demo01 (master)
$  git config --global user.email "ynparis@163.com"

nn@PARIS MINGW64 /d/workspace/flutter_app_demo01 (master)
$  git config --global user.name "YNParis"

-------------------------------------------------------------------------

问题:push代码时报错,无法关联到远程仓库。
nn@PARIS MINGW64 /d/workspace/flutter_app_demo01 (master)
$ git push origin master
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

解决:关联到远程仓库。
1.
nn@PARIS MINGW64 /d/workspace/flutter_app_demo01 (master)
$ git remote add origin git@github.com:YNParis/FlutterDome01.git

2.
nn@PARIS MINGW64 /d/workspace/flutter_app_demo01 (master)
$ git fetch origin
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), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:YNParis/FlutterDome01
 * [new branch]      master     -> origin/master

3.
nn@PARIS MINGW64 /d/workspace/flutter_app_demo01 (master)
$ git remote -v
origin  git@github.com:YNParis/FlutterDome01.git (fetch)
origin  git@github.com:YNParis/FlutterDome01.git (push)

4.
nn@PARIS MINGW64 /d/workspace/flutter_app_demo01 (master)
$ git branch -a
* master
  remotes/origin/master
  
问题:提交代码时版本落后
nn@PARIS MINGW64 /d/workspace/flutter_app_demo01 (master)
$ git push origin master
To github.com:YNParis/FlutterDome01.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:YNParis/FlutterDome01.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解决:拉取最新版本代码,合并后再提交。

问题:拉取代码时不关联的分支不能合并
nn@PARIS MINGW64 /d/workspace/flutter_app_demo01 (master)
$ git pull origin master
From github.com:YNParis/FlutterDome01
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

nn@PARIS MINGW64 /d/workspace/flutter_app_demo01 (master)
$

解决:加上--allow-unrelated-histories强制执行
nn@PARIS MINGW64 /d/workspace/flutter_app_demo01 (master)
$ git pull origin master --allow-unrelated-histories
From github.com:YNParis/FlutterDome01
 * branch            master     -> FETCH_HEAD
Auto-merging README.md
CONFLICT (add/add): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值