Git:获取分支上的最新提交

发布于 2024-07-12 05:53:50 字数 2079 浏览 8 评论 0原文

我正在努力理解有关 GIT 的一些事情。

我们有一个包含许多分支的存储库。 我可以获取这些分支之一的本地副本(git checkout -b ...),进行一些更改,然后将它们推回。 但是,如果我无法标记分支的末尾,其他用户如何获取分支的头部? 当他们使用 git checkout 获取分支时,他们会在分支点获取代码——而不是该分支的头部。

我在这里缺少什么?

编辑:我很晚才进入这个项目,并参与了 CVS 到 GIT 的转换。 我假设 FOO_3_4_0001... 标记以 FOO_3_4_0001_INITIAL 开头的分支上的所有标记点。 我该如何检查?

编辑2:感谢所有提供答案的人。 事实证明,标签 FOO_3_4_0001 不在 3.4 分支上,而这正是我一直以来所缺少的。 我已经安排了私刑派对。


@ghoseb,没有成功。 我尝试了这个:

16:19:29 (1) foo $ git checkout --track -b FOO_3_4_0001_INITIAL origin/FOO_3_4_0001_INITIAL
Branch FOO_3_4_0001_INITIAL set up to track remote branch refs/remotes/origin/FOO_3_4_0001_INITIAL.
Switched to a new branch "FOO_3_4_0001_INITIAL"
16:19:36 (1) foo $ git branch
* FOO_3_4_0001_INITIAL
  master
16:19:39 (1) foo $ git pull
remote: Counting objects: 68, done.
remote: Compressing objects: 100remote: % (59/59), done.
remote: Total 61 (delta 18), reused 0 (delta 0)
Unpacking objects: 100% (61/61), done.
From ssh://***
   f0c5a5f..99f6c1e  master     -> origin/master
Already up-to-date.
16:19:42 (1) foo $

此时我检查了我在这个分支上所做的更改,但它不在那里。 如果我查看标记为 FOO_3_4_0001_RC5a 的代码,我的更改就在那里。


好的,@Dustin 和 @mipadi 的更多信息。

当我运行 gitbranch -r 时,我看到:

16:12:02 (1) foo $ git branch -r
  origin/FOO_3_3_0001_BUILT_VF_BRANCH
  origin/FOO_3_4_0001_INITIAL
  origin/FOO_3_5_0000_RC5
  origin/FOO_3_5_0001_BRANCH
  origin/HEAD
  origin/master
  origin/origin
16:12:05 (1) foo $

如果我查看标签列表,我会看到:

16:12:05 (1) foo $ git tag -l
FOO_3_4_0000_RC1
FOO_3_4_0000_RC2
FOO_3_4_0000_RC2b
FOO_3_4_0000_RC3
FOO_3_4_0000_RC4
FOO_3_4_0000_RC4b
FOO_3_4_0000_RC5
FOO_3_4_0000_RELEASE
FOO_3_4_0000_TC1
FOO_3_4_0000_TC2
FOO_3_4_0001_RC2
FOO_3_4_0001_RC3
FOO_3_4_0001_RC4
FOO_3_4_0001_RC5
FOO_3_4_0001_RC5a
FOO_3_4_0001_TC1
16:14:33 (1) foo $

我面临的挑战是了解 FOO_3_4_0001_INITIAL 分支上的最新代码是什么。

现在,在这种情况下,我碰巧知道它是 FOO_3_4_0001_RC5a,但如果我不知道(我们的一些开发人员有时会遇到这种情况),我如何检查 origin_FOO_3_4_0001_INITIAL 分支知道我已经获得了最新的代码那个分行?

I'm struggling to understand something about GIT.

We've got a repository with a number of branches in it. I can fetch a local copy of one of those branches (git checkout -b ...), make some changes, then push them back. If I fail to tag the end of the branch, however, how do other users get the head of the branch? WHen they use git checkout to fetch the branch they get the code at the point of the branch -- not the head of that branch.

What am I missing here?

EDIT: I came into this project late and was involved in the CVS to GIT conversion. I am assuming that the FOO_3_4_0001... tags all mark points along the branch kicked off with FOO_3_4_0001_INITIAL. How can I check?

EDIT 2: Thanks to everyone who contributed answers. It turns out that tag FOO_3_4_0001 was not on the 3.4 branch and that's what I was missing all along. I have already arranged the lynching party.


@ghoseb, didn't work. I tried this:

16:19:29 (1) foo $ git checkout --track -b FOO_3_4_0001_INITIAL origin/FOO_3_4_0001_INITIAL
Branch FOO_3_4_0001_INITIAL set up to track remote branch refs/remotes/origin/FOO_3_4_0001_INITIAL.
Switched to a new branch "FOO_3_4_0001_INITIAL"
16:19:36 (1) foo $ git branch
* FOO_3_4_0001_INITIAL
  master
16:19:39 (1) foo $ git pull
remote: Counting objects: 68, done.
remote: Compressing objects: 100remote: % (59/59), done.
remote: Total 61 (delta 18), reused 0 (delta 0)
Unpacking objects: 100% (61/61), done.
From ssh://***
   f0c5a5f..99f6c1e  master     -> origin/master
Already up-to-date.
16:19:42 (1) foo $

At this point I checked for the change I made on this branch and it's not there. If I check out the code tagged FOO_3_4_0001_RC5a my change is there.


Ok, more info for @Dustin and @mipadi.

When I run git branch -r, I see:

16:12:02 (1) foo $ git branch -r
  origin/FOO_3_3_0001_BUILT_VF_BRANCH
  origin/FOO_3_4_0001_INITIAL
  origin/FOO_3_5_0000_RC5
  origin/FOO_3_5_0001_BRANCH
  origin/HEAD
  origin/master
  origin/origin
16:12:05 (1) foo $

And if I look at the list of tags, I see, among other things:

16:12:05 (1) foo $ git tag -l
FOO_3_4_0000_RC1
FOO_3_4_0000_RC2
FOO_3_4_0000_RC2b
FOO_3_4_0000_RC3
FOO_3_4_0000_RC4
FOO_3_4_0000_RC4b
FOO_3_4_0000_RC5
FOO_3_4_0000_RELEASE
FOO_3_4_0000_TC1
FOO_3_4_0000_TC2
FOO_3_4_0001_RC2
FOO_3_4_0001_RC3
FOO_3_4_0001_RC4
FOO_3_4_0001_RC5
FOO_3_4_0001_RC5a
FOO_3_4_0001_TC1
16:14:33 (1) foo $

The challenge I have is knowing what the latest code on the FOO_3_4_0001_INITIAL branch is.

Now in this instance I happen to know that it's FOO_3_4_0001_RC5a, but if I don't (as will sometimes be the case for some of our developers) how do I check out the origin_FOO_3_4_0001_INITIAL branch know that I've got the very latest code on that branch?

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

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

发布评论

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

评论(5

耳根太软 2024-07-19 05:53:51

只是为了确保我们没有忽视显而易见的事情:

当您进行更改时,您是否会在将其推回之前提交它们? Git分支指向分支上最新的提交,因此如果更改尚未提交,那么分支仍将指向分支点,这就是您所说的正在发生的情况。

Just to make sure we're not overlooking the obvious:

When you make changes, do you then commit them before pushing them back? Git branches point to the latest commit on the branch, so if the changes haven't been commited, then the branch will still point to the branch point, which is what you said is happening.

如果您正在谈论本地分支而不是远程分支,那么这两个分支都可以为您提供最新的提交哈希:

git rev-parse HEAD

git log -n 1 --pretty=format:"%H"  

尝试它们,它们应该是等效的

If you are talking about a local branch instead of remote branch, both of these work to give you the latest commit hash:

git rev-parse HEAD

and

git log -n 1 --pretty=format:"%H"  

try them both, they should be equivalent

她比我温柔 2024-07-19 05:53:50

他们只需从远程存储库中提取即可获取远程分支的 HEAD。

$ git remote update
$ git checkout <branch_name>
$ git pull origin <branch_name>
$ <edit> ...
$ git commit
$ git push origin <branch_name>

我这里假设远程存储库的名称为origin,您可以用实际名称替换它。

They can just pull from the remote repository to get the HEAD of the remote branch.

$ git remote update
$ git checkout <branch_name>
$ git pull origin <branch_name>
$ <edit> ...
$ git commit
$ git push origin <branch_name>

I have assumed the name of the remote repository as origin here, you can substitute it with the actual name.

意中人 2024-07-19 05:53:50

听起来好像您正在做正确的事情。 分支的名称只是指向分支上最新提交的指针。 您确定要将更改推送回每个人都从中提取的存储库吗? 当您提交时,您仅提交到您的本地存储库,因此要获取更改,协作必须 (a) 从本地存储库中提取,或 (b) 从其他可访问的存储库中提取您已使用 git push 推送更改。

It sounds like you're doing the right thing. The name of a branch is simply a pointer to the latest commit on the branch. Are you sure you're comming and pushing the changes back to the repo that everyone is pulling from? When you commit, you're only committing to your local repo, so to get changes, collaborations must either (a) pull from your local repo, or (b) pull from some other accessible repo to which you have pushed your changes using git push.

最冷一天 2024-07-19 05:53:50

Git 克隆、拉取和获取正在处理整个存储库树。
分支只是本地存储库中的标签。

完成克隆后,您将在源中拥有远程存储库的副本。
您可以通过在本地查看来访问它。

git co -b origin_local_master origin

这将创建原始主机的本地可编辑分支。

但您也可以访问此存储库内的分支。

git co -b origin_local_dev origin/dev

这将创建原始分支 dev 的本地可编辑分支。

Git clone, pull and fetch are working with the entire repository tree.
The branches are just tags inside your local repository.

When you have done a clone you have a copy of the remote repository in the origin.
You can access this by checking it out locally.

git co -b origin_local_master origin

This creates a local editable branch of the origin master.

But you can also access the branches inside this repository.

git co -b origin_local_dev origin/dev

This creates a local editable branch of the origin branch dev.

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