Skip to content

20210115关于git之后的计划

ziyouzy edited this page Jan 15, 2021 · 1 revision

可以使用:

git push -u origin --all
git push -u origin --tags

-u 相当于第一次串门的时候你登了个记办了个vip。。以后再来就知道是你来了。不用脱裤子搜身了

现在准备分别在gitee和github上创建两个备份仓库,而本地并不会拉取他们

而是在保留两者自身的主分支的前提下,push --all本地分支,让远程仓库独立存在需要做好备份的“根”

在具体操作中还用到了如下语句:

查询旧本地仓库的远程关联状态:git remote -v
解除旧仓库的当前远程关联:git remote remove origin
创建新关联:git remote add origin https://xxxxxxx/ziyouzy/xxx.git
其实并不需要解除,只要不适用这个origin这个名称即可,但是为了严谨解除关联

这里涉及到了一个git push --all与git push --mirror之间的区别:

https://stackoverflow.com/questions/49343025/git-push-all-vs-mirror
--all
Push all branches (i.e. refs under refs/heads/); cannot be used with other <refspec>.
--mirror
... specifies that all refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored ...

这解释简单明了,我需要的时mirror但是我想看一下refs目录目前都有什么:

zqy@ubuntu:~/WorkShop/golang/src/yunhuan_mylib/.git/refs$ ls
    heads  remotes  tags

    zqy@ubuntu:~/WorkShop/golang/src/yunhuan_mylib/.git/refs/heads$ ls
        buildService  master  snmpconn

    zqy@ubuntu:~/WorkShop/golang/src/yunhuan_mylib/.git/refs/remotes$ ls
        origin

    zqy@ubuntu:~/WorkShop/golang/src/yunhuan_mylib/.git/refs/tags$ ls
        (null)

嗯,我需要的是--mirror

正式开始进行创建副本的操作,执行的语句应该是:

git push github_yunhuanBackup --mirror

因为已经完成了关联,所以使用github_yunhuanBackup这个别名,之后也会有别名gitee_yunhuanBackup的相关操作,从而实现双备份

同时采用--mirror

最后一点是,需要先修改下远程仓库已存在主分支的名称(main)把其改成更合适的(我改成了bak)

这样做除了更加语义清晰之外,也是为了确保远程的这个主分支的名字不会与本地的名字造成冲突

于是执行git push github_yunhuanBackup --mirror(并没有指定一个远程的分支名称)就会默认自动创建分支名了

Counting objects: 958, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (871/871), done.
Writing objects: 100% (958/958), 140.66 MiB | 1.08 MiB/s, done.
Total 958 (delta 427), reused 0 (delta 0)
remote: Resolving deltas: 100% (427/427), done.
To [email protected]:ziyouzy/yunhuanBackup.git
 * [new branch]      buildService -> buildService
 * [new branch]      master -> master
 * [new branch]      snmpconn -> snmpconn
 ! [remote rejected] bak (refusing to delete the current branch: refs/heads/bak)
error: failed to push some refs to '[email protected]:ziyouzy/yunhuanBackup.git'

mirror操作尝试了将远程refs与本地同步,但是没有权限删除bak从而让两者彻底一致,不过我就希望这样

也并没有因为体积过大而被拒绝,万幸万幸啊,感觉挺好的

在向giteepush的时候同样遇到了这个问题:

remote: error: refusing to delete the current branch: refs/heads/bak
To [email protected]:ziyouzy/yunhuan-backup.git
 * [new branch]      buildService -> buildService
 * [new branch]      master -> master
 * [new branch]      snmpconn -> snmpconn
 * [new branch]      github_yunhuanBackup/buildService -> github_yunhuanBackup/buildService
 * [new branch]      github_yunhuanBackup/master -> github_yunhuanBackup/master
 * [new branch]      github_yunhuanBackup/snmpconn -> github_yunhuanBackup/snmpconn
 ! [remote rejected] bak (deletion of the current branch prohibited)
error: failed to push some refs to '[email protected]:ziyouzy/yunhuan-backup.git'

效果很好我很满足,就是希望这样

Clone this wiki locally