gpt4 book ai didi

git - Github for Mac 如何同步?

转载 作者:太空狗 更新时间:2023-10-29 13:28:25 24 4
gpt4 key购买 nike

根据Github for Mac blog announcement ,

Once you're ready to share your commits, or pull in remote commits — just press the Sync Branch button. We'll perform a smarter version of pull --rebase && push that reduces merge commits but doesn't rewrite your merges.

pull --rebase && push 的“更智能版本”是什么?他们到底在做什么?有没有可能在命令行上做这个“更聪明”的事情?

最佳答案

博文“Rebasing Merge Commits in Git”(来自 Glen Maddern )说明了 git pull --rebase 当您进行本地 merge 时的危险:

local merge

如果你现在在 origin/master 之上对 master 执行 git pull --rebase,你会删除你的本地 merge
看到 rebase 后的下一张图片:不再有 merge 提交。

no more merge commit

This is bad for a whole lot of reasons.

  • For one, the feature commits are actually duplicated, when really I only wanted to rebase the merge. If you later merge the feature branch in again, both commits will be in the history of master.
  • And origin/feature, which supposed to be finished and in master, is left dangling.
    Unlike the awesome history that you get from following a good branching/merging model, you’ve actually got misleading history.
    For example, if someone looks at the branches on origin, it’ll appear that origin/feature hasn’t been merged into master, even though it has! Which can cause all kinds of problems if that person then does a deploy. It’s just bad news all round.

这就是 Github for (Mac|Windows) 会检测和避免的。

如果你没有及时发现,同一篇博文提到了以下恢复:

[master] git reset --hard origin/master
HEAD is now at 9f3e34d sneaky extra commit
[master] git merge --no-ff feature

实际解决方案:

可以达到想要的效果:

desired result

Instead of using git pull --rebase, use a git fetch origin and git rebase -p origin/master

我想 pull --rebase 的“更智能版本”是“fetch + rebase 保留 merge ”的组合。

Glen还提出了 following aliases以反驳此命令序列将不再使用与本地分支关联的跟踪信息这一事实。

function git_current_branch() {
git symbolic-ref HEAD 2> /dev/null | sed -e 's/refs\/heads\///'
}

alias gpthis='git push origin HEAD:$(git_current_branch)'
alias grb='git rebase -p'
alias gup='git fetch origin && grb origin/$(git_current_branch)'

Jason Weathered发布了“http://jasoncodes.com/posts/gup-git-rebase ”,但现在指的是 git-up ,来自Aanand Prasad .

关于git - Github for Mac 如何同步?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12576384/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com