[英]What did I just do with my git repository?
I cloned a git repo and it had, among many others, these two remote branches: 我克隆了一个git repo,它有很多其他两个远程分支:
When I cloned it, I was on master. 当我克隆它时,我就掌握了。 I wanted to switch to the foo-bar
branch, ie I wanted to get the code from the remote origin/foo-bar
branch into a local branch of the name foo-bar
, so I did: 我想切换到foo-bar
分支,即我想将代码从远程origin/foo-bar
分支获取到名称为foo-bar
的本地分支,所以我这样做了:
$ git checkout foo-bar
Note that I wasn't sure if I was to say git checkout origin/foo-bar
or just git checkout foo-bar
. 请注意,我不确定是说git checkout origin/foo-bar
还是说git checkout foo-bar
。
Now, I am wondering which of the two did I end up doing? 现在,我想知道我到底做了哪两个?
Did I just create a new local branch named foo=bar
with all the contents of the master
branch? 我是否刚刚使用master
分支的所有内容创建了一个名为foo=bar
的新本地分支? OR 要么
Did I create a new branch named foo-bar
and automatically pull all contents from the remote origin/foo-bar
into it? 我是否创建了一个新的名为foo-bar
分支并将所有内容从远程origin/foo-bar
自动拉入其中?
If I did the wrong thing, ie I actually wanted to do #2 but if I did something else, how do I delete this local branch named foo-bar
? 如果我做错了事,即我实际上想做第二件事,但是如果我做了其他事,如何删除这个名为foo-bar
本地分支?
Note that I wasn't sure if I was to say
git checkout origin/foo-bar
or justgit checkout foo-bar
. 请注意,我不确定是说git checkout origin/foo-bar
还是说git checkout foo-bar
。
Both of these are valid, but they mean different things. 两者都是有效的,但它们的含义不同。 Tl;dr, you wanted the latter in this case. Tl; dr,在这种情况下,您需要后者。
origin/foo-bar
(where origin
in this case is the name of a remote) is a so-called remote tracking branch. origin/foo-bar
(在这种情况下, origin
是远程名称)是所谓的远程跟踪分支。 Remote tracking branches are read-only and cannot be checked out, so git checkout origin/foo-bar
will detach HEAD
and set it to the commit that origin/foo-bar
refers to. 远程跟踪分支是只读的,无法检出,因此git checkout origin/foo-bar
将分离HEAD
并将其设置为origin/foo-bar
引用的提交。
git checkout foo-bar
checks out the branch foo-bar
if it exists, or it creates it anew as described below. git checkout foo-bar
分支foo-bar
是否存在,或按如下所述重新创建它。
- Did I just create a new local branch named
foo-bar
with all the contents of themaster
branch? 我是否刚刚使用master
分支的所有内容创建了一个名为foo-bar
的新本地分支?
If your version of Git is not ancient, by default git checkout foo-bar
will create branch foo-bar
and set it up to track in your case origin/foo-bar
. 如果您的Git版本不是很旧,默认情况下git checkout foo-bar
将创建分支foo-bar
并将其设置为跟踪您的case origin/foo-bar
。
This behaviour is documented in the man page for git-checkout . 手册页git-checkout中记录了此行为。
- Did I create a new branch named foo-bar and automatically pull all contents from the remote
origin/foo-bar
into it? 我是否创建了一个新的名为foo-bar的分支并将所有内容从远程origin/foo-bar
自动拉入其中?
See 1. 请参阅1。
- If I did the wrong thing, ie I actually wanted to do #2 but if I did something else, how do I delete this local branch named foo-bar? 如果我做错了事,即我实际上想做#2,但是如果我做了其他事,如何删除这个名为foo-bar的本地分支?
To delete a branch, check out a different branch (eg git checkout master
) and then do git branch -d foo-bar
. 要删除分支,请签出其他分支(例如git checkout master
),然后执行git branch -d foo-bar
。
See man page for git-branch . 有关git-branch的信息,请参见手册页 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.