如何关闭 Git 分支?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8614112/
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 12:34:52  来源:igfitidea点击:

How to close off a Git Branch?

gitgithub

提问by Pure.Krome

so i'm starting out using Git + GitHub.

所以我开始使用 Git + GitHub。

In our little distributed team, each member is creating their own branch for each issue/requirement they are allocated.

在我们的小型分布式团队中,每个成员都为他们分配的每个问题/需求创建自己的分支。

  1. git branch Issue#1 <-- create this branch
  2. git checkout issue#1 <-- switch over to this branch
  1. git branch Issue#1 <-- create this branch
  2. git checkout issue#1 <-- switch over to this branch

now code code, commit, code, commit, etc...

现在code codecommitcodecommit,等...

then pull request, code-fixup, commit, code, commit.. etc.

然后pull request, code-fixup, commit, code, commit.. 等等。

and FINALLY ... pull request is accepted.

最后……接受拉取请求。

Woot.

呜。

but .. now what? (......awkward......)

但是..现在呢?(......尴尬的......)

Does the person who created the branch on their local dev machine need to .. close off the branch? A suggestion was for the dev person to delete the branch `( ... -D ...) and then do a pull / refresh of the master .. which then will get all their branch code.

在本地开发机器上创建分支的人是否需要关闭分支?一个建议是让开发人员删除分支 `( ... -D ...) 然后对 master .. 进行拉取/刷新,然后将获得他们所有的分支代码。

Hmmmmm... not sure - please help :)

嗯……不确定 - 请帮忙:)

回答by Bill Door

We request that the developer asking for the pull request state that they would like the branch deleted. Most of the time this is the case. There are times when a branch is needed (e.g. copying the changes to another release branch).

我们要求要求拉取请求的开发人员声明他们希望删除分支。大多数时候都是这种情况。有时需要一个分支(例如将更改复制到另一个发布分支)。

My fingers have memorized our process:

我的手指已经记住了我们的过程:

git checkout <feature-branch>
git pull
git checkout <release-branch>
git pull
git merge --no-ff <feature-branch>
git push
git tag -a branch-<feature-branch> -m "Merge <feature-branch> into <release-branch>"
git push --tags
git branch -d <feature-branch>
git push origin :<feature-branch>

A branch is for work. A tag marks a place in time. By tagging each branch merge we can resurrect a branch if that is needed. The branch tags have been used several times to review changes.

一个分支是为了工作。标签标记时间地点。通过标记每个分支合并,我们可以在需要时复活一个分支。分支标签已被多次用于更改。

回答by Gaurav Gupta

Yes, just delete the branch by running git push origin :branchname. To fix a new issue later, branch off from master again.

是的,只需通过运行删除分支git push origin :branchname。要稍后修复新问题,请再次从 master 分支。

回答by Dau

after complete the code first merge branch to master then delete that branch

完成代码后首先将分支合并到 master 然后删除该分支

git checkout master
git merge <branch-name>
git branch -d <branch-name>