東川印記

一本東川,笑看爭龍斗虎;寰茫兦者,度橫佰昧人生。

github fork 自己项目

2021年3月10日星期三



自己一个模板项目A,希望能基于模板项目扩展实现项目B,基于项目B实现后续业务项目。。。。

一开始考虑 建org,发现免费的org不行,有想着新建个账号,发现  新账号 不能 fork B .....

然后搜了下,果然已经有人 已经遇到过。。。。

1,原项目删分支,分支变为B的master

SENRSL:sample2-struct senrsl$ git branch
* koin
  master
SENRSL:sample2-struct senrsl$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
SENRSL:sample2-struct senrsl$ git branch -d koin
warning: deleting branch 'koin' that has been merged to
         'refs/remotes/origin/koin', but not yet merged to HEAD.
Deleted branch koin (was 7bca1e2).
SENRSL:sample2-struct senrsl$ git s
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
SENRSL:sample2-struct senrsl$ git branch
* master
SENRSL:sample2-struct senrsl$ git push origin --delete koin
To github.com:senRsl/sample2-struct.git
 - [deleted]         koin
SENRSL:sample2-struct senrsl$ git s
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
SENRSL:sample2-struct senrsl$ git remote -v
origin    git@github.com:senRsl/sample2-struct.git (fetch)
origin    git@github.com:senRsl/sample2-struct.git (push)
SENRSL:sample2-struct senrsl$ git branch -a
* master
  remotes/origin/master
SENRSL:sample2-struct senrsl$

2,github建新项目B,本地指向上级项目A

SENRSL:temp senrsl$ git clone git@github.com:senRsl/sample2-struct-koin.git
Cloning into 'sample2-struct-koin'...
warning: You appear to have cloned an empty repository.
SENRSL:temp senrsl$ cd sample2-struct-koin/
SENRSL:sample2-struct-koin senrsl$ git branch
SENRSL:sample2-struct-koin senrsl$ git remote -v
origin    git@github.com:senRsl/sample2-struct-koin.git (fetch)
origin    git@github.com:senRsl/sample2-struct-koin.git (push)
SENRSL:sample2-struct-koin senrsl$ git remote add upstream git@github.com:senRsl/sample2-struct.git
SENRSL:sample2-struct-koin senrsl$ git remote -v
origin    git@github.com:senRsl/sample2-struct-koin.git (fetch)
origin    git@github.com:senRsl/sample2-struct-koin.git (push)
upstream    git@github.com:senRsl/sample2-struct.git (fetch)
upstream    git@github.com:senRsl/sample2-struct.git (push)
SENRSL:sample2-struct-koin senrsl$ git pull upstream master
remote: Enumerating objects: 891, done.
remote: Counting objects: 100% (891/891), done.
remote: Compressing objects: 100% (455/455), done.
remote: Total 891 (delta 239), reused 812 (delta 160), pack-reused 0
Receiving objects: 100% (891/891), 170.15 KiB | 195.00 KiB/s, done.
Resolving deltas: 100% (239/239), done.
From github.com:senRsl/sample2-struct
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> upstream/master
SENRSL:sample2-struct-koin senrsl$ git branch
* master
SENRSL:sample2-struct-koin senrsl$ git push origin master
Counting objects: 891, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (376/376), done.
Writing objects: 100% (891/891), 170.18 KiB | 233.00 KiB/s, done.
Total 891 (delta 239), reused 891 (delta 239)
remote: Resolving deltas: 100% (239/239), done.
To github.com:senRsl/sample2-struct-koin.git
 * [new branch]      master -> master
SENRSL:sample2-struct-koin senrsl$

推送B项目的master完成,此时B.master == A.master

3,复制A.koin 为 B.master提交

两个方案:

1)删除B.master内所有文件,仅保留.git隐藏文件夹。

     然后复制 A.koin除.git文件夹外所有文件至B.master提交。

 2)A的复制品koin分支改为master分支,A的复制品项目再走一遍步骤2,把koin提交为B.master

方案1遗失了原先的git记录。

方案2保留完整但操作麻烦;

方案2:

撤销方案2所有操作。

cp A的复制品 为 sample2-struct-koin

重建github:senRsl/sample2-struct-koin

2.1)修改指向

删除远程地址,重新增加新地址

SENRSL:sample2-struct-koin senrsl$ git branch
* koin
  master
SENRSL:sample2-struct-koin senrsl$ git remote -v
origin    git@github.com:senRsl/sample2-struct.git (fetch)
origin    git@github.com:senRsl/sample2-struct.git (push)
SENRSL:sample2-struct-koin senrsl$ git remote rm origin
SENRSL:sample2-struct-koin senrsl$ git remote -v
SENRSL:sample2-struct-koin senrsl$ git remote add origin git@github.com:senRsl/sample2-struct-koin.git
SENRSL:sample2-struct-koin senrsl$ git remote -v
origin    git@github.com:senRsl/sample2-struct-koin.git (fetch)
origin    git@github.com:senRsl/sample2-struct-koin.git (push)
SENRSL:sample2-struct-koin senrsl$

2.2)删除分支

SENRSL:sample2-struct-koin senrsl$ git branch
* koin
  master
SENRSL:sample2-struct-koin senrsl$ git branch -d master
Deleted branch master (was 6e8b659).
SENRSL:sample2-struct-koin senrsl$ git branch
* koin
SENRSL:sample2-struct-koin senrsl$

2.3)修改分支名

SENRSL:sample2-struct-koin senrsl$ git branch -m koin master
SENRSL:sample2-struct-koin senrsl$ git branch
* master
SENRSL:sample2-struct-koin senrsl$

2.4) 推送分支

SENRSL:sample2-struct-koin senrsl$ git push origin master
Counting objects: 1028, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (716/716), done.
Writing objects: 100% (1028/1028), 186.33 KiB | 720.00 KiB/s, done.
Total 1028 (delta 280), reused 0 (delta 0)
remote: Resolving deltas: 100% (280/280), done.
To github.com:senRsl/sample2-struct-koin.git
 * [new branch]      master -> master
SENRSL:sample2-struct-koin senrsl$

github上并不能显示关联,怎么感觉有种多此一举。。。。

2.5)增加父指向

SENRSL:sample2-struct-koin senrsl$ git branch
* master
SENRSL:sample2-struct-koin senrsl$ git remote -v
origin    git@github.com:senRsl/sample2-struct-koin.git (fetch)
origin    git@github.com:senRsl/sample2-struct-koin.git (push)
SENRSL:sample2-struct-koin senrsl$ git remote add upstream git@github.com:senRsl/sample2-struct.git
SENRSL:sample2-struct-koin senrsl$ git pull upstream master
From github.com:senRsl/sample2-struct
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> upstream/master
Already up to date.
SENRSL:sample2-struct-koin senrsl$ git branch
* master
SENRSL:sample2-struct-koin senrsl$

的确感觉很奇怪,不过看一下这个线的走势还是有点作用的。。。。

至少在本地还是有点作用的,在github看起来完全就是两个不相关项目。。。。


--
senRsl
2021年03月10日19:24:12

没有评论 :

发表评论