2016年1月26日 星期二

[實作] Git 同步(刪除)遠端與本地端 Tag

#Delete local tags.
git tag -l | xargs git tag -d
#Fetch remote tags.
git fetch --tags origin
#Delete remote tags.
git tag -l | xargs git push --delete origin
#Delete local tasg.
git tag -l | xargs git tag -d
簡單說明語法,
刪除所有本地端的Tag
git tag -l | xargs git tag -d
重新抓取(Fetch)所有遠端的Tag  (這時本地端與遠端的Tag 已經是一致的了)
git fetch --tags origin
這裡用了點小手段,將本地的所Tag 列出,並推送(push)到遠端刪除 ,
因為在上一步驟執行後,本地與遠端的Tag 是一致的,所以遠端所有Tag 都將被刪除
git tag -l | xargs git push --delete origin
再次刪除所有本地端的Tag,這樣本地與遠端的Tag就都刪除完畢
git tag -l | xargs git tag -d


同場加映

在windows 10 底下,透過SourceTree的CustomAction,
同步刪除遠端與本地端的Tag。
  1. 首先準備一個SyncRemoveTags.sh檔
    #Delete local tags.
    echo 'Remove all local tags'
    git tag -l | xargs git tag -d
    #Fetch remote tags.
    echo 'Fetch tags from origin'
    git fetch --tags origin
    #Delete remote tags.
    echo 'Remove tags from origin and local'
    git tag -l | xargs git push --delete origin
    #Delete local tasg.
    git tag -l | xargs git tag -d
    說明:
    • 刪除本地所有Tag
    • 重新抓取(fetch)origin所有Tag
    • 將本地的所Tag 列出,並推送(push)到遠端刪除(因為在上一步驟執行後,本地與遠端的Tag 是一致的,所以遠端所有Tag 都將被刪除)
    • 刪除本地所有Tag
  2. 準備一份Call-Git-bash-SyncRemoveTags.bat,內容如下:

    cd %1
    C:\Users\admin\AppData\Local\Atlassian\SourceTree\git_local\git-bash.exe D:\Bat\SyncRemoveTag.sh
    注意:
    這是呼叫git-bash.exe去執行SyncRemoveTags.sh ,所以要注意git-bash的路徑(一般來說有安裝SourceTree就會有),與步驟1的SyncRemoveTags.sh所在位置的路徑。
    請依實際位置修改。 之所以這樣操作是為了讓
    SourceTree呼叫git-bash (Customer Action預設會執行command),再透過git-bash 呼叫去操作git tag
  3. 在Source Tree上選擇Tools => Options,切換至Custom Actions => Add
  4. 輸入名稱"Sync Remove Tags",選擇之前的檔案Call-Git-bash-SyncRemoveTags.bat,並加入參數"$REPO",Show Full Output可勾可不勾
  5. 之後就可以直接在選單上使用Custom Actions > Sync Remove Tags的功能了


沒有留言:

張貼留言