我可以在我的git项目上设法导航思考不同的分支机构

发布于 2025-01-17 15:24:44 字数 460 浏览 3 评论 0原文

我正在开发我的第一个 GIT 存储库,它有几个分支。通过这节课,我们要在不同的分支之间进行切换。

目前,我已经在 Visual Code Studio 上克隆了存储库,它运行良好。项目在vscode上正常打开。

当我尝试切换分支时,它不起作用。 当我输入:gitbranch时,它只显示:* main

不过,该项目应该有更多的分支! 这是 git 链接:https: //github.com/OpenClassrooms-Student-Center/debuggez-l-interface-de-votre-site/tree/main

I'm working on my first GIT repo, which has several branches. Through the lesson, we have to switch between different branches.

At the moment , I've been cloning on Visual Code Studio the repo, which is working fine. The project opens normally on vscode.

When I try to switch branches, it doesn't work.
When I type : git branch it only shows me : * main.

However, there should be more branches on the project!
Here is the git link : https://github.com/OpenClassrooms-Student-Center/debuggez-l-interface-de-votre-site/tree/main

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

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

发布评论

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

评论(2

荭秂 2025-01-24 15:24:44

当我输入:git分支时,它只显示:* main

默认情况下,gitbranch显示本地分支。

当您获取存储库时,其分支以远程分支开始 - 它们仍然会被获取,但仅在remotes/repo/branchname下开始。

  • 运行 gitbranch [--list] -r|--remote 来查看这些。

当您创建跟踪远程分支的本地分支时,默认情况下会对 master -> 执行此操作。 remotes/origin/master (或者在您的情况下为 main ->remotes/origin/main),那么您就有一个本地分支。

  • 运行 gitbranch [--list] 来查看这些。

您想查看所有分支:

  • 运行gitbranch [--list] -a|--all来查看所有内容。

当您签出尚不存在但与远程分支名称匹配的本地分支时,它将被设置为正确跟踪远程,即使您在简单运行 gitbranch 时看不到它代码>.

当我尝试切换分支时,它不起作用

但你没有尝试切换分支。您查看存在哪些分支(没有意识到它只显示本地分支),但从未实际运行 git checkout partie-1/chapitre-1/section-1 或其他内容。正确的?

即使在了解上述内容之前,您也应该对尝试这样做感到放松:如果出现问题,您随时可以再次删除分支,并且签出失败不会产生任何副作用。如果您拼错了分支名称,它不会破坏您的存储库或丢失您的工作。

您还应该养成检查在线文档的习惯。运行 git helpbranch 会显示所有这些选项。


输出示例:

$ git branch
* main

$ git branch -r
  remotes/origin/HEAD -> origin/main
  remotes/origin/main
  remotes/origin/partie-1/chapitre-1/section-1

$ git branch -a
* main
  remotes/origin/HEAD -> origin/main
  remotes/origin/main
  remotes/origin/partie-1/chapitre-1/section-1

PS。同一分支同时拥有本地和远程版本的原因是它们可能会有所不同:您需要能够在不更改本地副本的情况下获取远程版本,以便比较它们并决定要做什么来解决这个问题(通常是合并或变基)。

When I type : git branch it only shows me : * main

By default git branch shows local branches.

When you fetch a repo, its branches start out as remote branches - they're still fetched, but start off only under remotes/repo/branchname.

  • Run git branch [--list] -r|--remote to see these.

When you create a local branch that tracks a remote branch, as is done by default for master -> remotes/origin/master (or in your case for main -> remotes/origin/main), then you have a local branch.

  • Run git branch [--list] to see these.

You want to see all branches:

  • run git branch [--list] -a|--all to see everything.

When you checkout a local branch that doesn't already exist, but matches the name of a remote branch, it will be set up to track the remote correctly even though you couldn't see it when simply running git branch.

When I try to switch branches, it doesn't work

But you didn't try to switch branches. You looked to see what branches existed (without realizing it only showed the local ones) and never actually ran git checkout partie-1/chapitre-1/section-1 or whatever. Right?

You should feel relaxed about trying this even before you knew the above: you can always delete the branch again if something went wrong, and checkout failing has no side-effects whatsoever. If you mis-spell a branch name, it isn't going to ruin your repo or lose your work.

You should also get in the habit of checking the online documentation. Running git help branch shows all these options.


Sample output:

$ git branch
* main

$ git branch -r
  remotes/origin/HEAD -> origin/main
  remotes/origin/main
  remotes/origin/partie-1/chapitre-1/section-1

$ git branch -a
* main
  remotes/origin/HEAD -> origin/main
  remotes/origin/main
  remotes/origin/partie-1/chapitre-1/section-1

PS. The reason for having both local and remote versions of the same branch is that they can diverge: you need to be able to fetch the remote version without altering your local copy, in order to compare them and decide what to do about it (usually merging or rebasing).

浮生未歇 2025-01-24 15:24:44

如果您仅在本地克隆中看到main分支,则您可能想执行 git提取 获取远程存储库中存在的所有其他分支。

If you only see the main branch in your local clone your might want to do a git fetch to get all the other branches that exist in the remote repository.

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