简体   繁体   English

为什么我需要一个本地 master 分支?

[英]Why do I need a local master branch?

Our team is using git for quite some time, but still this thing escapes me.我们的团队使用 git 已经有一段时间了,但是这件事还是让我措手不及。 I'm constantly getting conflicts with my files that have been merged earlier, and vacuous diffs with the files modified by other team members.我经常与之前合并的文件发生冲突,并且与其他团队成员修改的文件之间存在空白差异。 Usually, it happens in my branch merged earlier, and it is quite laborious to resolve these issues to get clean mergereq...通常,它发生在我较早合并的分支中,解决这些问题以获得干净的合并是相当费力的...

Therefore, I'm trying to simplify the development process as much as possible, to have it nuisance-error-resilient as SVN.因此,我试图尽可能地简化开发过程,让它像 SVN 一样具有抗干扰能力。 Can I have one local branch sourced from origin/master which I merge every week?我可以每周合并一个来自 origin/master 的本地分支吗? What do I need to do to keep it not stale, is egit pull just enough?我需要做什么才能让它不陈旧,egit pull 就够了吗? Or do I have to dance through或者我必须跳舞通过

git checkout master
git pull
git checkout my_branch
git merge master

every time?每次? The first command obviously creates local master, which answers my question in the title, but why egit pull wouldn't be just enough?第一个命令显然创建了本地 master,它回答了我在标题中的问题,但为什么 egit pull 还不够?

Git doesn't know that commits have been made to master at origin unless you update the local repo somehow--usually either with a fetch or pull . Git 不知道在原始位置已经向 master 提交了,除非您以某种方式更新本地存储库——通常是使用fetchpull This means that if you just merge your local copy of master you may be merging an obsolete head state, which can cause problems when you try to push.这意味着,如果您只是合并 master 的本地副本,您可能正在合并一个过时的 head state,这可能会在您尝试推送时导致问题。

You don't need a local master branch.您不需要本地主分支。 You can avoid that hassle by merging the remote branch:您可以通过合并远程分支来避免这种麻烦:

git merge origin/master

I like this workflow which uses a combination of reset --hard and rebase :我喜欢这个工作流程,它结合了reset --hardrebase

  1. Hard override local master with remote origin/master具有远程源/主站的硬覆盖本地主站
git checkout master
git fetch --all
git reset --hard origin/master
  1. Rebase current development branch to master.将当前的开发分支重新设置为 master。 Note: Use rebase to avoid 'merge commits'.注意:使用 rebase 来避免“合并提交”。
git checkout feature
git rebase master
  1. And yes, I do this all the time.是的,我一直这样做。 Technically one could rebase directly to the origin/master, but I like to keep things in sync as much as possible.从技术上讲,可以直接变基到 origin/master,但我喜欢尽可能保持同步。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将本地 Git 分支推送到远程的 master 分支? - How do I push a local Git branch to master branch in the remote? 在创建新分支后也需要从master到本地本地仓库的git pull安全吗?我也需要在该分支上查看最新更改? - Is it safe to do a git pull from master to my local repo after creating a new branch on which I need to see the latest changes too? 如何删除本地分支并返回主节点? - How do I delete a local branch and go back to master? 如何将正在进行的本地 master 和分支移动到另一台笔记本电脑? - How do I move a local master and branch in progress to another laptop? 为什么我需要git merge origin / master中的“master”? - Why do I need the “master” in git merge origin/master? Git:在特征分支中压缩或重新建立基础时,为什么需要将其与另一个分支(例如master)进行比较? - Git: When squashing or rebasing in a feature branch, why do you need to compare it to another branch like master? 为什么我需要选择我的分支主机 - Why do i require to select my branch master 为什么我只在github上看到我的master分支? - Why do I only see my master branch on github? 当我需要* pull * origin master时,为什么它会说“你的分支在857提交之前领先于原点/主人” - why does it say “Your branch is ahead of origin/master by 857 commits” when I need to *pull* origin master 如何在不更改主分支的情况下更改本地 git 存储库的功能分支? - How do I change a feature branch of a local git repo without changing the master branch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM