简体   繁体   English

git远程分支结帐

[英]git remote branch checkout

I create new repository on github and made few commits, according to github web interface, my repository has two branches master and HEAD , when I switch from master to HEAD , I'm seeing my files. 我在github上创建了新的存储库,并进行了很少的提交,根据github Web界面,我的存储库有两个分支masterHEAD ,当我从master切换到HEAD ,我正在查看文件。

I'd like to get checkout of HEAD on my local drive: 我想在本地驱动器上签出HEAD

[alexus@j ~]$ git clone https://github.com/a1exus/jt4cb.git
Cloning into 'jt4cb'...
remote: Counting objects: 32, done.
remote: Total 32 (delta 5), reused 5 (delta 5), pack-reused 26
Unpacking objects: 100% (32/32), done.
Checking connectivity... done.
[alexus@j ~]$ cd jt4cb/
[alexus@j ~/jt4cb]$ git branch --all
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
[alexus@j ~/jt4cb]$ ls
README.md
[alexus@j ~/jt4cb]$ 

How do I get to my files from my local checkout? 如何从本地结帐处获取文件?

Please advise. 请指教。

* UPDATE * *更新*

I updated my question with better wording to explain my actual issue and end goal. 我用更好的措词更新了我的问题,以解释我的实际问题和最终目标。

HEAD is a pointer to the tip of your branch. HEAD是指向分支尖端的指针。 Right now, it's pointing to the tip of master. 现在,它指向主人的尖端。

If you want that, just check out your master branch. 如果需要,只需签出您的master分支即可。

git checkout master

There is no such concept in Git as the remote branch HEAD as far as I know. 据我所知,Git中没有远程分支HEAD概念。 HEAD is simply the tip of the current branch or commit where you are. HEAD只是当前分支或提交所在位置的提示。

Git uses remote tracking branches to bridge between your local Git setup and what is happening with the actual remote branches. Git使用远程跟踪分支在本地Git设置和实际的远程分支之间进行桥接。 In your case, there is a tracking branch called origin/master which tracks the remote master branch. 在您的情况下,有一个名为origin/master的跟踪分支,它跟踪远程master分支。 The command git fetch is what updates your remote tracking branch. git fetch命令可以更新您的远程跟踪分支。 If you want to point your HEAD to the remote master branch, the following commands, which you were already doing, will accomplish this: 如果要将HEAD指向远程master分支,则已经在执行的以下命令将完成此操作:

git checkout master
git pull

After this, your local master will be in sync with the remote. 此后,您的本地master将与遥控器同步。 If you ever want to see the difference between the remote master and your local one without actually updating your local master , you can try the following: 如果您希望在不实际更新本地master情况下看到远程master和本地master之间的区别,可以尝试以下操作:

git fetch
git diff master origin/master

Another option to "test drive" the remote master would be to create a temporary local branch: “测试驱动器”远程master另一种选择是创建一个临时的本地分支:

git fetch
git checkout -b temp_master origin/master

You can explore the temporary branch, and then delete it once you are finished. 您可以浏览临时分支,然后在完成后将其删除。

master is a branch, HEAD is a pointer to top commit in current branch master是一个分支, HEAD是指向当前分支中最高提交的指针

From git checkout doc , you will see 从git checkout doc中 ,您将看到

The git checkout command serves three distinct functions: checking out files, checking out commits, and checking out branches. git checkout命令提供三个不同的功能:检出文件,检出提交和检出分支。 In this module, we're only concerned with the first two configurations. 在本模块中,我们仅关注前两个配置。

I would highly recommend you to read the full doc. 我强烈建议您阅读完整的文档。

git checkout master

Return to the master branch. 返回到master分支。 Branches are covered in depth in the next module, but for now, you can just think of this as a way to get back to the “current” state of the project. 在下一个模块中深入介绍了分支,但就目前而言,您可以将其视为回到项目“当前”状态的一种方式。

git checkout <commit>
git checkout HEAD

Update all files in the working directory to match the specified commit. 更新工作目录中的所有文件以匹配指定的提交。 You can use either a commit hash or a tag as the <commit> argument. 您可以使用提交哈希或标记作为<commit>参数。 This will put you in a detached HEAD state. 这将使您处于分离的HEAD状态。

You can use HEAD which will point to the last commit. 您可以使用HEAD ,它指向最后一次提交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM