简体   繁体   English

在 git 中查找本地 repo 和远程 repo 之间的差异

[英]Find differences between local repo and remote repo in git

I'm currently working from two different computers on a project - a laptop running Linux, and a desktop running Win7.我目前在一个项目的两台不同的计算机上工作——一台运行 Linux 的笔记本电脑和一台运行 Win7 的台式机。 I'm using an ubuntu server with gitolite on it to host my repos.我正在使用带有 gitolite 的 ubuntu 服务器来托管我的存储库。

I'm trying to write a quick script that will do two things:我正在尝试编写一个快速脚本来做两件事:

  1. Check if anything has changed on the local repo, since the last push.自上次推送以来,检查本地仓库是否有任何变化。 If so, it should commit changes, push the commit to the remote repo如果是这样,它应该提交更改,将提交推送到远程仓库

    1a. 1a。 I'm not sure how this works, but I DONT want this commit to overwrite changes in files that I haven't changed locally (ie: they may have been changed on the other computer, and pushed)我不确定这是如何工作的,但我不希望此提交覆盖我在本地未更改的文件中的更改(即:它们可能已在另一台计算机上更改并推送)

  2. After that, it should check if the remote repo has any files that have been changed since my last pull (see 1a.).之后,它应该检查远程仓库是否有自我上次拉取以来已更改的任何文件(参见 1a。)。 If so, pull those changes into the local repo.如果是这样,请将这些更改拉入本地存储库。

The intention of this script is to keep both computers synced with each other, without having to manually do all of this git work each time.此脚本的目的是使两台计算机彼此同步,而不必每次都手动完成所有 git 工作。 I would like to have this run periodically (once every half hour?), so I don't want it to take a huge amount of resources, if possible.我想定期运行(每半小时一次?),所以如果可能的话,我不希望它占用大量资源。

I don't need the whole script written for me (unless it is just a couple lines) - just point me towards the commands I will need.我不需要为我编写的整个脚本(除非它只是几行) - 只需将我指向我需要的命令。

Compare the output of:比较 output 的:

git ls-remote <remote>
git show-ref

Although generally what is done is to fetch (not pull) the remote and compare the remote branches with your local branches.虽然通常所做的是获取(而不是拉取)远程并将远程分支与本地分支进行比较。 If you have non-fast forward merges, you can't really automate because manual intervention on the merge will be required before pushing again.如果您有非快进合并,则无法真正实现自动化,因为在再次推送之前需要对合并进行手动干预。

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

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