当同名文件存在时,Git改变分支 [英] Git change branch when file of same name is present

查看:480
本文介绍了当同名文件存在时,Git改变分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的git repo中有一个名为xyz的文件。巧合的是,我也有一个名为xyz的分支。目前我在主人,但我想结账到分支xyz。要使用的命令很简单

  $ git checkout xyz 

但是这会将文件xyz签出到当前的HEAD中。如何将我的分支更改为分支xyz?

commit a047faf (git 1.8.4.3+),你也可以试试:

  git checkout xyz  -  

这将清楚表明 xyz 部分是分支或提交,而 - 之后的所有内容都必须是路径(这里没有提供路径)。请参阅有关双连字符约定的更多信息



如果你可以尝试不使用' - ',这可能会或可能不起作用,如为什么git checkout < remote_branchname> 不会创建新的跟踪分支?


git checkout name 确实:




  • 如果它是一个跟踪路径,则将其重置

  • 如果它是远程分支,则创建一个跟踪分支并切换到它。

其行为并不总是相同。因此,' - '提供了明确的消歧。


I have in my git repo, a file named xyz. Coincidently, I also have a branch named xyz. Presently I am on master, but I want to checkout to branch xyz. The command to be used is simple

$ git checkout xyz

But this would checkout the file xyz to the present HEAD. How would I change my branch to branch xyz?

解决方案

As illustrated by commit a047faf (git 1.8.4.3+), you can also try:

git checkout xyz --

That would make clear that the xyz part is a branch or commit, while everything after -- must be a path (here no path is provided). See more here on the double-hyphen convention.

If you try without the '--', that might or might not work, as shown in "Why does git checkout <remote_branchname> not create new tracking branch?":

git checkout name does:

  • if it's local branch or explicit remote branch, switch to it.
  • if it's a tracked path, reset it
  • if it's a remote branch, create a tracking branch and switch to it.

And its behavior isn't always the same. Hence the '--' to provide a clear disambiguation.

这篇关于当同名文件存在时,Git改变分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆