简体   繁体   English

如何在git分支上获取最新的结帐提交?

[英]how to get the latest checkout commit on git branch?

I am looking to make a software update using git. 我希望使用git进行软件更新。 It means that the client has a local clone of the remote git repository and from a swing interface it will see the children commits of his current commit , meaning all commits newer than his current commit. 这意味着客户端具有远程git存储库的本地克隆,并且从swing接口将看到其当前提交的子提交 ,这意味着所有提交都比其当前提交新。

Then the client will check the desired commit from the list of the newer commits and make an update to that commit. 然后,客户端将从较新的提交列表中检查所需的提交,并对该提交进行更新。

In order to execute git commands, I create few methods using ProcessBuilder. 为了执行git命令,我使用ProcessBuilder创建了一些方法。

To test the behavior I have 2 local repositories, and one remote repository. 为了测试行为,我有2个本地存储库和一个远程存储库。 1. in localRepo1 I clone the remoteRepo, then I write a text into a newFile and I commit it, then push it. 1.在localRepo1中,我克隆remoteRepo,然后将文本写入newFile,然后提交并提交。 2 in localRepo2 I clone the remoteRepo: it is now a full copy of the remote repo, so it have the newFile also. 2在localRepo2中,我克隆了remoteRepo:它现在是远程仓库的完整副本,因此它也有newFile。 3 from the localRepo1 I am writing a newFile2 containing another text and push it to the remote repository. 3从localRepo1开始我正在编写一个包含另一个文本的newFile2并将其推送到远程存储库。 4 from the localRepo2 I want to see the difference that I only have a commit, not 2. I mean, in localRepo2 I only have the newFile, not the files newFile and newFile2. 4从localRepo2我想看到的区别是我只有一个提交,而不是2。我的意思是,在localRepo2中我只有newFile,没有文件newFile和newFile2。

I am testing with 2 terminals: int the first I am in the directory localRepo1, and the second terminal is in the directory localRepo2. 我正在使用2个终端进行测试:int第一个终端在localRepo1目录中,第二个终端在localRepo2目录中。

executing 执行中

git rev-list --all --date-order 

in each local repos, then I can clearly see the differences: 在每个本地存储库中,我可以清楚看到差异:

localRepo1: localRepo1:

82d8715010cab1a6649ebecb6adeff9c3c88d85f
a2ad1c5ab691fc63a283d7dde85014606ed85f62
c8757e4f8ff318260577e479e3c9146f79aebacf

localRepo2: localRepo2:

a2ad1c5ab691fc63a283d7dde85014606ed85f62
c8757e4f8ff318260577e479e3c9146f79aebacf

I am looking for a command to see that missing commit: 我正在寻找一个命令来查看丢失的提交:

82d8715010cab1a6649ebecb6adeff9c3c88d85f

This missing commit is the one that the client will see into a swing component (comboBox for example - there can be more missing commits) and can check to update to. 这种丢失的提交是客户端将看到的一个摆动组件(例如,comboBox-可能会有更多丢失的提交),并且可以检查更新。

How can I see these differences? 我如何看到这些差异?

I found a satisfying solution: 我找到了一个令人满意的解决方案:

git fetch origin

then 然后

git whatchanged ..origin/<branchName>

exp: 经验值:

git whatchanged ..origin/maste

I can think of two ways. 我可以想到两种方式。

What I would recommend is, don't push. 我建议您不要推。 Instead have your client software fetch. 取而代之的是获取您的客户端软件。 Then the client's local branch remains correctly on the commit they're using, and the fetch gets them a remote branch ref reflecting the latest available commit. 然后,客户端的本地分支正确地保留在他们正在使用的提交上,并且获取将使他们获得反映最新可用提交的远程分支引用。

git rev-list --reverse origin/master..master

will show the available commits to which an update is possible, and once one is chosen the client software can (fast-forward) merge the chosen commit into the local branch. 将显示可能进行更新的可用提交,并且一旦选择了该提交,客户端软件就可以(快进)将所选提交合并到本地分支中。

( rev-list instead of log because the former is better for scripted parsing) rev-list而不是log因为前者更适合脚本分析)

The only down side is that you need to define when the client software will check for updates. 唯一的缺点是您需要定义客户端软件何时检查更新。 If that's not possible... well, I don't believe it. 如果那不可能...好吧,我不相信。 But if you refuse to solve it that way: 但是,如果您拒绝以这种方式解决它:

Maintain two branches. 维持两个分支。 The one you push to, and the one the client is actually on. 您推送到一个,而客户端实际在运行。 Start the two on the same commit, and only update the client branch by (fast-forward) merging from the push branch. 在相同的提交上启动两者,并且仅通过(快进)与推送分支合并来更新客户端分支。

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

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