在git中,如何将我的标签与远程服务器同步?

时间:2012-05-08 00:59:44

标签: git git-tag

有没有办法让我的本地git标签与远程标签保持同步?也就是说 - 不仅在创建时获取新标记(通常,在fetch - ing / pull - 时),而且还不再在远程上修剪标记,并在其他人时删除现有标记git push -f'标签。 我知道我可以git fetch remotename后跟git remote prune remotename来实现分支的类似行为。

8 个答案:

答案 0 :(得分:40)

以下对我有用:

git fetch --prune --tags

答案 1 :(得分:17)

一些研究表明 git 无法区分本地或外来标签(所有标签都转到.git / refs / tags /)。因此,无法确定本地创建的标记和可修剪的远程标记之间的差异。然后将这些选项简化为:拥有不断增长的标记集,或仅包含服务器上的标记。

git push --tags origin && \
git tag | xargs -n1 git tag -d && \
git fetch --tags

删除后一行为的第一行,并且可能是频繁使用的git别名。

另一种方法是在标记点创建一个分支(因为它们可以被标识为本地/远程),并且永远不会再写入它。然后使用remotename / branchname作为结帐标记会使代码保持同步(除了git fetchgit remote prune remotename)。

无论哪种方式都是黑客攻击,“正确”的答案是不断更改标签。

答案 2 :(得分:16)

  

...也不再在遥控器上修剪标签

git fetch获得Git 2.17(2018年第二季度)获得的便利 摆脱本地持有的陈旧标签。

请参阅commit 6317972commit 97716d2commit e249ce0commit 627a129commit d0e0747commit 2c72ed7commit e1790f9,{{3} },commit 59caf52commit 82f34e0commit 6fb23f5commit ca3065ecommit bf16ab7commit eca142dcommit 750d0dacommit 0711883commit ce3ab21(2018年2月9日)commit aa59e0e (由Ævar Arnfjörð Bjarmason (avar)合并于Junio C Hamano -- gitster --,2018年3月6日)

  

获取:添加--prune-tags选项和fetch.pruneTags config

     

--prune-tags添加git-fetch选项,以及fetch.pruneTags配置选项和-P简写(-p--prune)。<登记/>   这允许执行以下任何一项:

git fetch -p -P
git fetch --prune --prune-tags
git fetch -p -P origin
git fetch --prune --prune-tags origin
     

或者简单地说:

git config fetch.prune true &&
git config fetch.pruneTags true &&
git fetch
     

而不是更冗长:

git fetch --prune origin 'refs/tags/*:refs/tags/*' '+refs/heads/*:refs/remotes/origin/*'
     

在此功能之前,支持拉动的用例很痛苦   来自已删除其分支标签的repo   定期,并让我们的本地参考反映上游。

     

在工作中,我们在每个卷展栏的回购中创建部署代码,并且   那些很多,所以他们会在几周内归档   表现原因。

     

如果没有此更改,很难集中配置此类存储库   /etc/gitconfig(在仅用于处理的服务器上)   他们)。您需要全局设置fetch.prune=true,然后为每个设置git -C {} config --replace-all remote.origin.fetch "refs/tags/*:refs/tags/*" "^\+*refs/tags/\*:refs/tags/\*$"   回购:

fetch.pruneTags=true
     

现在我也可以在/etc/gitconfig中设置 git pull ,   和运行&#34; function record(){ this.event } record.prototype = { start: function (){ keyUp = Rx.Observable.fromEvent(document, "keyup"); this.event = keyUp.subscribe((key) => {console.log(key)}); }, stop: function (){ this.event.unsubscribe(); } } rec = new record(); rec.start(); setTimeout(rec.stop, 2000); &#34;的用户将自动进行修剪   我想要的语义。

答案 3 :(得分:6)

另一个对我有用的解决方案:

                               Date Pallets Lt Tt
            1  28/12/2011     491 NA NA
            2  29/12/2011     385 NA 0.787890411
            3  30/12/2011     662 NA NA
            4  31/12/2011      28 NA NA
            5  01/01/2012      46 NA NA
            6  02/01/2012     403 NA NA
            7  03/01/2012     282 NA NA
            8  04/01/2012     315 NA NA
            9  05/01/2012     327 NA NA
            10 06/01/2012     458 NA NA

答案 4 :(得分:5)

git push --tags会将本地标记推送到服务器。默认情况下,git fetch(git pull的前半部分或git pull --rebase)会提取标签,但你可以指定-t或--tags来拉取所有标签。

我不确定如何修剪远程删除的标签,但是提取应该下拉任何强制更新的标签。

答案 5 :(得分:4)

免责声明这使用git内部(有些人可能会认为文件系统 是一个git界面,但那是另一天:D)

# Blow away all local tags, this will remove any that are tagged locally
# but are not on the remote
rm .git/refs/tags/*

# Download all the tags from the remote
git fetch --tags

答案 6 :(得分:0)

这是另一种解决方案:

 - name: Test PsExec
   hosts: windows
   tasks:
   - name: Copy PsExec
     win_copy:
       src: <WORKING_FOLDER>/PsExec.exe
       dest: "{{ ansible_user_dir }}/Desktop/PsExec.exe"
       force: no

   - name: Run Windows Calculator
     win_command: "{{ ansible_user_dir }}/Desktop/psexec.exe -accepteula -nobanner -i 1 -s calc.exe"
     register: output
   - debug: var=output

来自PsExec doc:

  

-p   --prune

     

在获取之前,删除不再有的任何远程跟踪引用   存在于遥控器上。如果标签不受修剪,则不受修剪   仅由于默认标记自动跟踪或由于a而获取   --tags选项。但是,如果由于显式refspec 而获取标记(在命令行或远程配置中,   例如,如果使用--mirror选项克隆远程,则然后是它们   也需要修剪

答案 7 :(得分:0)

使用这些命令同步标签(删除所有本地标签,然后获取所有远程标签)

git tag -d $(git tag) # delete all local tags
git fetch --all # fetch all remote to local