簡體   English   中英

將GIT存儲庫(和提交歷史記錄)移動到當前為空的另一個存儲庫

[英]Moving GIT repository (and commit history) to another repository currently empty

我在GIT存儲庫repA有一個代碼,我需要將其移到當前為空但現在在repB具有repA的提交和標記歷史記錄的另一個存儲庫repB中。

關於此過程的工作流程/命令有什么建議嗎?
提前致謝!

您只需要添加新的遙控器,然后將代碼推送到新的倉庫即可

git remote add origin2 <url>
git push origin2 <branch name>

這是一個即時消息,即時消息用於簽出所有分支並將其推送到新的遠程站點

# first add the new rmeote
git remote add origin2 <new-url> 


#!/bin/bash

# loop over all the original branches
# 1. check them out as local branches 
# 2. set the origin as the track branch
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
    git branch --track ${branch#remotes/origin2/} $branch
done

# now push all branches and tags
git push origin2 --all    
git push origin2 --tags

該腳本有什么作用?

git branch -a
獲取所有本地分支機構的列表

| grep remotes | grep remotes分支名稱為:'remotes / origin /',因此將從分支名稱中刪除遠程

| grep -v HEAD | grep -v master
刪除主節點(當前分支)和HEAD ,這是最新提交的別名

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM