git 中的“简单”与“当前”push.default 用于去中心化工作流程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23918062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 18:08:38  来源:igfitidea点击:

"simple" vs "current" push.default in git for decentralized workflow

gitgit-pushgit-config

提问by void.pointer

Functionally speaking, in a decentralized workflow, I don't see the difference between simpleand currentoptions for push.defaultconfig setting.

从功能上讲,在去中心化的工作流程中,我看不到simple和配置设置current选项之间的区别push.default

currentwill push the current branch to an identically named branch on the specified remote. simplewill effectively do the same thing as well for both the tracked and any untracked remotes for the current branch (it enforces identical branch names in both cases).

current将当前分支推送到指定远程上的同名分支。simple对于当前分支的已跟踪和任何未跟踪的遥控器也将有效地执行相同的操作(它在两种情况下都强制执行相同的分支名称)。

Can someone explain any important differences between the two for decentralized workflows that I am missing?

有人可以解释我遗漏的分散工作流两者之间的任何重要区别吗?

回答by

The difference is that with simple, git push(without passing a refspec) will fail if the current branch isn't tracking a remote upstream branch (even if a branch with the same name exists on the remote):

不同之处在于simplegit push如果当前分支没有跟踪远程上游分支(即使远程上存在具有相同名称的分支),则 with , (不传递 refspec)将失败:

$ git checkout -b foo
Switched to a new branch 'foo'

$ git config push.default simple
$ git push
fatal: The current branch foo has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin foo

On the other hand, currentdoesn't care about whether or not the current branch tracks an upstream, it just wants to push to any branch that has the same name:

另一方面,current不关心当前分支是否跟踪上游,它只想推送到任何具有相同名称的分支:

$ git config push.default current
$ git push
Total 0 (delta 0), reused 0 (delta 0)
To /Documents/GitHub/bare
 * [new branch]      foo-> foo

The Documentation

文档

From the Git configuration documentation:

Git 配置文档

  • upstream- push the current branch to its upstream branch...

  • simple- like upstream, but refuses to push if the upstream branch's name is different from the local one...

  • current- push the current branch to a branch of the same name.

  • upstream- 将当前分支推送到其上游分支...

  • simple- 类似上游,但如果上游分支的名称与本地分支名称不同,则拒绝推送...

  • current- 将当前分支推送到同名分支。

回答by jthill

The difference is that simplepushes to its tracking branch if it has the same name, while currentwill push to a branch of the same name regardless of any tracking branch:

不同之处在于,simple如果它具有相同的名称,则推送到其跟踪分支,而current不管任何跟踪分支,都会推送到同名的分支:

$ git branch -vvv
  master 58d9fdc [origin/master: ahead 1] t1 bobo
* new    37132d3 [origin/save: ahead 1] t1 bibi   # <- tracking branch 'save'

$ git -c push.default=current push                # <- set `push.default=current`
Counting objects: 3, done.
Writing objects: 100% (3/3), 234 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /home/jthill/sandbox/20/t1
 * [new branch]      new -> new                   # <- and push creates `new`