如何查看或保护远程分支删除?

发布于 2024-11-14 23:44:12 字数 478 浏览 1 评论 0原文

在我的项目中,我为新功能创建了一个新分支,完成了该功能并将该分支合并回我的开发分支。然后,我按照说明在本地和我的 github 原始存储库上删除了分支。

然后我注意到所有提到我的分支,无论是本地还是远程,都完全消失了。我看不到任何迹象表明该分支在某个时间点甚至存在过。这很可怕,因为如果我引入另一个开发人员(或者如果我这样做的话见鬼),而不是删除 GitHub 上的功能分支,而是删除开发分支,该怎么办?我得到的唯一迹象是少了一个分支,但没有任何迹象表明原因。

使用源代码控制的主要原因之一是拥有源代码中发生的所有事情的完整历史记录,这似乎与它相反,除非我遗漏了一些东西。我更喜欢的是某种方式将分支标记为关闭,这样它就不再接受任何更改,但是您仍然拥有分支进展的日志,谁关闭了它以及为什么关闭它(该功能是否不起作用正确输出,必须重做,是否完成,等等..)以及谁关闭了它。

由于我找不到任何方法来做到这一点,是否有任何方法至少可以确保谁可以删除分支以及谁无权访问它?或者有没有办法查看已删除的分支?

In my project I created a new branch for a new feature, finished the feature and merged the branch back into my development branch. I then followed the instructions to delete the branch locally and on my github origin repo.

I then noticed that all mentions of my branch, both locally and remotely, are completely gone. I can't see any indication that the branch even existed at some point of time. This is scary because what if I bring another developer on (or hell if I even do this) and instead of deleting a feature branch on GitHub he deletes the development branch. The only indication I will have is one less branch showing up with no indication of why.

One of the major reasons to use source control is to have a complete history of everything that happened to your source, and this seems to run contrary to it, unless I am missing something. What I would prefer is some way to mark a branch as closed so it doesn't accept any more changes, but you still have the log of the progression of the branch, who closed it and why it was closed (did the feature not work out correctly and it had to be redone, was it finished, etc..) and who closed it.

Since I can't find any way to do that is there any way to at least secure who is allowed to delete a branch and who doesn't have access to it? Or is there a way to view deleted branches?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故人爱我别走 2024-11-21 23:44:12

在git中删除一个分支确实会删除该分支。如果这不是您想要做的,请不要删除该分支。但是,单独删除分支并不会删除任何项目历史记录;它只是删除对分支末尾的引用。分支上的所有提交仍然存在;只是没有明显的方法来找到它们。

您无法阻止有权访问您的存储库的人删除分支。这就是为什么在 github 中每个人通常都有自己的存储库可以工作。如果删除了一个分支,那么你就是删除它的人。

如果您自己错误地删除了一个分支,如果您知道该分支尖端的提交 ID(该 ID 将记录在您将其合并到主开发行的提交中,或在引用日志中),则可以将其恢复。使用已删除分支的名称创建并签出一个新分支,然后使用 git reset 再次将该分支名称与提示提交联系起来。

从你的问题来看,你似乎想永远跟踪分支的状态。正确的方法是在分支末尾创建一个标签。然后,您可以删除该分支,但对提示(及其所有历史记录)的引用将保留在标签中。

Deleting a branch in git does really delete the branch. If this is not what you want to do, don't delete the branch. However, deleting a branch by itself doesn't remove any of your project history; it just removes the reference to the end of the branch. All the commits on the branch are still there; there's just no obvious way to find them.

You can't prevent someone who has access to your repository from deleting a branch. That's why it's usual in github for every person to have their own repository to work in. If a branch is deleted, you're the one who did it.

If you delete a branch yourself by mistake, you can get it back if you know the commit id of the tip of the branch (which will be recorded in the commit where you merged it into your main development line, or in the reflog). Create and checkout a new branch with the name of the deleted branch, and use git reset to tie that branch name with the tip commit again.

From your question, it seems like you want to keep track of the state of the branch forever. The right way to do that is to create a tag at the end of the branch. You can then delete the branch but the reference to the tip (and all its history) will live on in the tag.

野侃 2024-11-21 23:44:12

如果其他开发人员删除了 Github 上的分支,您的本地存储库中仍会保留该分支的副本,并且只需将其重新推送到 Github 即可。

If the other developer deletes a branch on Github, you'd still have your own copy of it in your local repo, and could just re-push it to Github.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文