[电机应用]

Git命令之删除远程仓库分支以及添加远程仓库 其它常用命令

[复制链接]
699|22
手机看帖
扫描二维码
随时随地手机跟帖
lxs0026|  楼主 | 2022-7-31 22:43 | 显示全部楼层 |阅读模式
git branch -r -d origin/branch-name
git push origin :branch-name
1.先查看远程分支
git branch -r
zhaojr@zhaojr-OptiPlex-7040:~/project/test_8227l/test_AndroidO_8827LGO/art$ git branch -r
  m/master -> origin/master
  origin/AC8227L-AndroidO_1024x600
  origin/android-trunk-o1.ac8227L
  origin/master
  origin/mt8227LGO_Devlopment


使用特权

评论回复
lxs0026|  楼主 | 2022-7-31 22:44 | 显示全部楼层
使用下面两条命令来删除远程分支
删除远程分支:

使用特权

评论回复
lxs0026|  楼主 | 2022-7-31 22:45 | 显示全部楼层
git branch -r -d origin/AC8227L-AndroidO_1024x600

使用特权

评论回复
lxs0026|  楼主 | 2022-7-31 22:47 | 显示全部楼层
执行git branch -r -d origin/AC8227L-AndroidO_1024x600之前:
zhaojr@zhaojr-OptiPlex-7040:~/project/test_8227l/test_AndroidO_8827LGO/art$ git branch -a
  AC8227L-AndroidO_1024x600
  android-trunk-o1.ac8227L
* mt8227LGO_Devlopment
  remotes/m/master -> origin/master
  remotes/origin/AC8227L-AndroidO_1024x600
  remotes/origin/android-trunk-o1.ac8227L
  remotes/origin/master
  remotes/origin/mt8227LGO_Devlopment

执行git branch -r -d origin/AC8227L-AndroidO_1024x600之后:
zhaojr@zhaojr-OptiPlex-7040:~/project/test_8227l/test_AndroidO_8827LGO/art$ git branch -a
  AC8227L-AndroidO_1024x600
  android-trunk-o1.ac8227L
* mt8227LGO_Devlopment
  remotes/m/master -> origin/master
  remotes/origin/android-trunk-o1.ac8227L
  remotes/origin/master
  remotes/origin/mt8227LGO_Devlopment

使用特权

评论回复
lxs0026|  楼主 | 2022-7-31 23:00 | 显示全部楼层
删除远程分支:

2、git push origin :AC8227L-AndroidO_1024x600  即可git push origin <空格>:AC8227L-AndroidO_1024x600  

使用特权

评论回复
lxs0026|  楼主 | 2022-7-31 23:02 | 显示全部楼层
zhaojr@zhaojr-OptiPlex-7040:~/project/test_8227l/test_AndroidO_8827LGO/art$ git branch -r
  m/master -> origin/master
  origin/android-trunk-o1.ac8227L
  origin/master
  origin/mt8227LGO_Devlopment

zhaojr@zhaojr-OptiPlex-7040:~/project/test_8227l/test_AndroidO_8827LGO/art$ git branch -a
  MT8827LGO_Devlopment
  android-trunk-o1.ac8227L
* mt8227LGO_Devlopment
  remotes/m/master -> origin/master
  remotes/origin/android-trunk-o1.ac8227L
  remotes/origin/master
  remotes/origin/mt8227LGO_Devlopment

使用特权

评论回复
lxs0026|  楼主 | 2022-7-31 23:05 | 显示全部楼层
.删除本地分支

git branch -D AC8227L-AndroidO_1024x600

使用特权

评论回复
lxs0026|  楼主 | 2022-7-31 23:07 | 显示全部楼层
执行之前:
zhaojr@zhaojr-OptiPlex-7040:~/project/test_8227l/test_AndroidO_8827LGO/art$ git branch -a
  AC8227L-AndroidO_1024x600
  android-trunk-o1.ac8227L
* mt8227LGO_Devlopment
  remotes/m/master -> origin/master
  remotes/origin/android-trunk-o1.ac8227L
  remotes/origin/master
  remotes/origin/mt8227LGO_Devlopment
执行之后:
zhaojr@zhaojr-OptiPlex-7040:~/project/test_8227l/test_AndroidO_8827LGO/art$ git branch -a
  android-trunk-o1.ac8227L
* mt8227LGO_Devlopment
  remotes/m/master -> origin/master
  remotes/origin/android-trunk-o1.ac8227L
  remotes/origin/master
  remotes/origin/mt8227LGO_Devlopment

使用特权

评论回复
lxs0026|  楼主 | 2022-7-31 23:08 | 显示全部楼层
清除当前代码库的所有修改,回到刚拉代码时:

使用特权

评论回复
lxs0026|  楼主 | 2022-7-31 23:08 | 显示全部楼层
git checkout . && git clean -xdf
git pull

使用特权

评论回复
lxs0026|  楼主 | 2022-7-31 23:12 | 显示全部楼层
删除代码库中 .git和.git*相关的所有文件和目录:
find . -name ".git" | xargs rm -Rf
find -name '.git*' |xargs rm -rf

使用特权

评论回复
lxs0026|  楼主 | 2022-7-31 23:13 | 显示全部楼层
修改代码库远程库的名称和添加代码库远程指向:

修改代码库远程库的名称:
修改代码库远程指向:
git remote set-url 远程库的名称  远程库的路径
该命令用于修改远程库的名称
如android代码中的art库:
git remote set-url origin  git@172.168.1.63:atc/android/o/platform/art

zhaojiawei@zhaojingrong-S2600CP:~/ATC_AndoridOGO_8827L-mirror/art$ git remote -v
autochips       ssh://b_flyaudio001@release.autochips.com:29418/atc/android/o/platform/art (fetch)
autochips       ssh://b_flyaudio001@release.autochips.com:29418/atc/android/o/platform/art (push)

zhaojiawei@zhaojingrong-S2600CP:~/ATC_AndoridOGO_8827L-mirror/art$ git remote set-url flyaudio        ssh://b_flyaudio001@release.autochips.com:29418/atc/android/o/platform/art

zhaojiawei@zhaojingrong-S2600CP:~/ATC_AndoridOGO_8827L-mirror/art$git remote -v
flyaudio        ssh://b_flyaudio001@release.autochips.com:29418/atc/android/o/platform/art (fetch)
flyaudio        ssh://b_flyaudio001@release.autochips.com:29418/atc/android/o/platform/art (push)

使用特权

评论回复
lxs0026|  楼主 | 2022-7-31 23:13 | 显示全部楼层
添加代码库远程指向:

添加代码库远程指向:
git remote add 远程库的名称  远程库的路径

该命令用于添加远程代码库

如android代码中的art库:
git remote add origin  git@172.168.1.63:atc/android/o/platform/art

zhaojiawei@zhaojingrong-S2600CP:~/ATC_AndoridOGO_8827L-mirror/art$ git remote -v
autochips       ssh://b_flyaudio001@release.autochips.com:29418/atc/android/o/platform/art (fetch)
autochips       ssh://b_flyaudio001@release.autochips.com:29418/atc/android/o/platform/art (push)

zhaojiawei@zhaojingrong-S2600CP:~/ATC_AndoridOGO_8827L-mirror/art$ git remote add origin git@172.168.1.63:/home/git/atc/android/o/platform/art

zhaojiawei@zhaojingrong-S2600CP:~/ATC_AndoridOGO_8827L-mirror/art$git remote -v
autochips       ssh://b_flyaudio001@release.autochips.com:29418/atc/android/o/platform/art (fetch)
autochips       ssh://b_flyaudio001@release.autochips.com:29418/atc/android/o/platform/art (push)
origin  git@172.168.1.63:/home/git/atc/android/o/platform/art (fetch)
origin  git@172.168.1.63:/home/git/atc/android/o/platform/art (push)

使用特权

评论回复
lxs0026|  楼主 | 2022-7-31 23:15 | 显示全部楼层
将多重指向全部拉到本地:
将本地库的多重指向拉到本地代码库中:
git fetch 远程代码库名

zhaojiawei@zhaojingrong-S2600CP:~/ATC_AndoridOGO_8827L-mirror/art$ git remove -v
autochips       ssh://b_flyaudio001@release.autochips.com:29418/atc/android/o/platform/art (fetch)
autochips       ssh://b_flyaudio001@release.autochips.com:29418/atc/android/o/platform/art (push)
other   git@172.168.1.63:/home/git/atc/android/o/platform/art (fetch)
other  git@172.168.1.63:/home/git/atc/android/o/platform/art (push)

zhaojiawei@zhaojingrong-S2600CP:~/ATC_AndoridOGO_8827L-mirror/art$ git branch -a
* android-trunk-o1.ac8227L
  remotes/autochips/android-trunk-o1.ac8227L
  remotes/m/android-trunk-o1.ac8227L -> autochips/android-trunk-o1.ac8227L
  remotes/origin/android-trunk-o1.ac8227L

zhaojiawei@zhaojingrong-S2600CP:~/ATC_AndoridOGO_8827L-mirror/art$ git fetch other
zhaojiawei@zhaojingrong-S2600CP:~/ATC_AndoridOGO_8827L-mirror/art$ git branch -a
* android-trunk-o1.ac8227L
  remotes/autochips/android-trunk-o1.ac8227L
  remotes/other/android-trunk-o1.ac8227L
  remotes/m/android-trunk-o1.ac8227L -> autochips/android-trunk-o1.ac8227L
  remotes/origin/android-trunk-o1.ac8227L
完成后other/android-trunk-o1.ac8227L就是我们从other远程库git@172.168.1.63:/home/git/atc/android/o/platform/art上拉下来的android-trunk-o1.ac8227L分支

使用特权

评论回复
lxs0026|  楼主 | 2022-7-31 23:21 | 显示全部楼层
如果本地已经有了分支,之前已经将代码checkout出来,那么执行以下命令:

git pull 远程名称  分支名称:分支名称

使用特权

评论回复
lxs0026|  楼主 | 2022-7-31 23:22 | 显示全部楼层
zhaojiawei@zhaojingrong-S2600CP:~/20181025_8227LGO/art$ git branch -a
  other_mt8227LGO_Devlopment
* mt8227LGO_Devlopment
  remotes/m/master -> origin/master
  remotes/origin/AC8227L-AndroidO_1024x600
  remotes/origin/android-trunk-o1.ac8227L
  remotes/origin/master
  remotes/origin/mt8227LGO_Devlopment
  remotes/other/mt8227LGO_Devlopment
other_mt8227LGO_Devlopment分支是由other/mt8227LGO_Devlopment基础上checkout出来
那么我们更新这个分支的最新代码更新可以执行以下命令:
zhaojiawei@zhaojingrong-S2600CP:~/20181025_8227LGO/art$ git pull other mt8227LGO_Devlopment:mt8227LGO_Devlopment
zhaojiawei@zhaojingrong-S2600CP:~/20181025_8227LGO/art$ git branch -a
* other_mt8227LGO_Devlopment
  mt8227LGO_Devlopment
  remotes/m/master -> origin/master
  remotes/origin/AC8227L-AndroidO_1024x600
  remotes/origin/android-trunk-o1.ac8227L
  remotes/origin/master
  remotes/origin/mt8227LGO_Devlopment
  remotes/other/mt8227LGO_Devlopment

zhaojiawei@zhaojingrong-S2600CP:~/20181025_8227LGO/art$ git branch log

使用特权

评论回复
tpgf| | 2022-8-2 15:10 | 显示全部楼层
远程通讯是什么方式啊

使用特权

评论回复
qcliu| | 2022-8-2 15:18 | 显示全部楼层
git指令是固定模式吗

使用特权

评论回复
drer| | 2022-8-2 15:25 | 显示全部楼层
如果操作失败了怎么处理呢

使用特权

评论回复
coshi| | 2022-8-2 15:32 | 显示全部楼层
这个需要非常熟悉指令表吧

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则