开源项目导入本地代码服务器(gitblit)
流程
1. 拉取代码
$ git clone git@gitee.com:beecue/fastbee.git
Cloning into 'fastbee'...
remote: Enumerating objects: 23324, done.
remote: Total 23324 (delta 0), reused 0 (delta 0), pack-reused 23324 (from 1)
Receiving objects: 100% (23324/23324), 368.67 MiB | 2.72 MiB/s, done.
Resolving deltas: 100% (10052/10052), done.
Updating files: 100% (1835/1835), done.
查看代码远程地址
$ git remote -v
origin git@gitee.com:beecue/fastbee.git (fetch)
origin git@gitee.com:beecue/fastbee.git (push)
移除远程仓库关联
$ git remote rm origin
再次查看项目的远程仓库地址
$ git remote -v
添加本地仓库远程关联
bobby@▒ƶ▒▒▒▒▒Ͱ MINGW64 /d/my/fastb/fastbee (master)
$ git remote add origin ssh://admin@127.0.0.1:29418/open/fastbee.git
bobby@▒ƶ▒▒▒▒▒Ͱ MINGW64 /d/my/fastb/fastbee (master)
$ git remote -v
origin ssh://admin@127.0.0.1:29418/open/fastbee.git (fetch)
origin ssh://admin@127.0.0.1:29418/open/fastbee.git (push)
代码冲突
忘记本地代码库初始化了,导致推送时出现问题。
bobby@▒ƶ▒▒▒▒▒Ͱ MINGW64 /d/my/fastb/fastbee (master)
$ git push -u origin --all
Password authentication
(admin@127.0.0.1) Password:
Password authentication
(admin@127.0.0.1) Password:
To ssh://127.0.0.1:29418/open/fastbee.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'ssh://127.0.0.1:29418/open/fastbee.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解决冲突
拉取远程合并到本地
bobby@▒ƶ▒▒▒▒▒Ͱ MINGW64 /d/my/fastb/fastbee (master)
$ git pull origin master
Password authentication
(admin@127.0.0.1) Password:
From ssh://127.0.0.1:29418/open/fastbee
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
Git 检测到 本地和远程的提交历史不相关(unrelated histories),并拒绝自动合并。
强制合并(允许不相关历史)
bobby@▒ƶ▒▒▒▒▒Ͱ MINGW64 /d/my/fastb/fastbee (master)
$ git pull origin master --allow-unrelated-histories
Password authentication
(admin@127.0.0.1) Password:
From ssh://127.0.0.1:29418/open/fastbee
* 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.
查看冲突文件
bobby@▒ƶ▒▒▒▒▒Ͱ MINGW64 /d/my/fastb/fastbee (master|MERGING)
$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both added: README.md
解决冲突后提交
bobby@▒ƶ▒▒▒▒▒Ͱ MINGW64 /d/my/fastb/fastbee (master|MERGING)
$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both added: README.md
$ git add README.md
bobby@▒ƶ▒▒▒▒▒Ͱ MINGW64 /d/my/fastb/fastbee (master|MERGING)
$ git commit
[master 8c8e411f] Merge branch 'master' of ssh://127.0.0.1:29418/open/fastbee
bobby@▒ƶ▒▒▒▒▒Ͱ MINGW64 /d/my/fastb/fastbee (master)
$ git push -u origin --all
Password authentication
(admin@127.0.0.1) Password:
Enumerating objects: 22911, done.
Counting objects: 100% (22911/22911), done.
Delta compression using up to 16 threads
Compressing objects: 100% (11060/11060), done.
Writing objects: 100% (22909/22909), 368.64 MiB | 20.62 MiB/s, done.
Total 22909 (delta 9807), reused 22816 (delta 9776), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (9807/9807)
remote: Updating references: 100% (1/1)
To ssh://127.0.0.1:29418/open/fastbee.git
96fe478c..8c8e411f master -> master
branch 'master' set up to track 'origin/master'.
完成导入本地代码库


浙公网安备 33010602011771号