修复 git 警告:“更新当前签出的分支;这可能会引起混乱”

发布于 2024-09-06 08:21:37 字数 595 浏览 5 评论 0原文

我一直在做一个工作流程,在远程中央存储库上创建 git 存储库,在本地开发计算机上克隆该存储库,做一些工作,然后将更改推回远程服务器上的同一存储库。

然而,我相信这是在我最近对 ​​git 进行更新之后,在推送更改后,我收到以下警告:

 Counting objects: 2724, done.
 Delta compression using up to 2 threads.
 Compressing objects: 100% (2666/2666), done.
 Writing objects: 100% (2723/2723), 5.90 MiB | 313 KiB/s, done.
 Total 2723 (delta 219), reused 0 (delta 0)
 warning: updating the currently checked out branch; this may cause confusion,
 as the index and working tree do not reflect changes that are now in HEAD.

有人可以向我解释这个警告的确切含义,以及我在我的代码中做错了什么吗?工作流程不会收到此警告?

I've been doing a workflow of making a git repository on a remote central repository, cloning that repo on my local dev machine, doing some work, and then pushing the changes back to the same repo on the remote server.

However, and I believe this was after an update I did to git recently, after pushing up a change, I'm getting the following warning:

 Counting objects: 2724, done.
 Delta compression using up to 2 threads.
 Compressing objects: 100% (2666/2666), done.
 Writing objects: 100% (2723/2723), 5.90 MiB | 313 KiB/s, done.
 Total 2723 (delta 219), reused 0 (delta 0)
 warning: updating the currently checked out branch; this may cause confusion,
 as the index and working tree do not reflect changes that are now in HEAD.

Can someone explain to me exactly what this warning means, and what I'm doing wrong in my workflow to not receive this warning?

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

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

发布评论

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

评论(1

画尸师 2024-09-13 08:21:39

Git 有两种类型的存储库。一种是您查看的常规存储库。另一个是“裸回购”。前者包含代码的工作副本以及托管历史记录的 .git 目录。您可以从这样的存储库进行克隆,但如果您尝试推回其中,.git 目录内的项目状态很可能与索引(暂存区域)不同步,并且存储库上的工作副本。

这是您看到的警告。解决这个问题的方法是让你的“远程中央存储库”成为一个裸存储库。您可以使用 git init --bare 来完成此操作。如果您这样做,则无法将其用作工作区。它只能用作遥控器。现在你可以推入它并从中拉出,但不能直接在那里工作。

Git has two types of repositories. One is your regular repo which you check out. The other is a "bare repo". The former contains a working copy of your code along with a .git directory that hosts the history. You can clone from such a repository but if you try to push back into it, it's quite possible that the state of the project inside the .git directory becomes out of sync with the index (staging area) and the working copy on the repository.

This is the warning you're seeing. The way to fix it would be to make your "remote central repository" a bare repo. You can do this using git init --bare. If you do this, you can't use this as a work area. It can only be used as a remote. Now you can push to this and pull from it but can't work directly over there.

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