如何自动更新我的远程仓库的服务器副本? [英] How to automate an update of a server copy of my remote repo?

查看:32
本文介绍了如何自动更新我的远程仓库的服务器副本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有版本控制 GUI 工具(例如 SourceTree)的工作流程是这样的.我在命令行中输入它.我的本地机器上有一个本地仓库.我有一个服务器(AWS EC2 实例),里面有我的本地存储库的副本.我将 Bitbucket 用于我的远程存储库.第一部分(本地,见下面的代码)我在我的本地机器上做的.然后我使用 SSH 和命令行连接我的 EC2 服务器并输入第二部分,git fetch, get merge:

My workflow without version control GUI tools (like SourceTree, for example) is like this. I type it in command line. I have a local repo on my local machine. And I have a server (AWS EC2 instance) with a copy of my local repo. And I use Bitbucket for my remote repo. The first part (local, see code below) I do in my local machine. Then I connect my EC2 server using SSH and a command line and type the the second part, git fetch, get merge:

# On local repo:
$ git add .
$ git commit -m "Commit message"
$ get push origin foo-branch

# On remote repo
$ git fetch origin
$ git merge origin/foo-branch

对于第一部分,我有像 SourceTree 这样的 GUI 工具.但是对于第二部分,我仍然必须使用命令行来获取和应用服务器上的更改.

For the first part I have GUI tools like SourceTree. But for the second part I still have to use command line to fetch and apply changes on my server.

我的问题是,是否有一些工具可以使流程自动化.这样就没有必要在命令行中使用 SSH 连接服务器并键入 git fetchgit merge.

My question is, is there some tools that allow to automate the process. So that it would be unnecessary to connect the server with SSH in command line and type git fetch and git merge.

例如,我只是在我的本地机器上推送一个提交(例如使用 SourceTree),我的服务器会自动检测它并获取和合并更改.

For example, I just push a commit on my local machine (using SourceTree, for example) and my server automatically detects it and fetches and merges changes.

推荐答案

不,远程 git repo 无法执行合并操作,因为 remote repo 是一个没有工作目录的裸仓库.所以git fetchgit merge等命令不能用于远程repo.

No, remote git repo can’t execute merge operation since remote repo is a bare repo which has no working directory. So the commands like git fetch, git merge can’t be used for remote repo.

您可以在本地存储库中使用 pre-push hook 的解决方法:在将 foo-branch 推送到远程之前,将触发 pre-push 钩子,然后您可以更新您的 master 分支并将 foo-branch 合并到 master 中.预推送钩子脚本如下:

The work around you can use a pre-push hook in your local repo: before you push foo-branch to remote, the pre-push hook will be triggerd, then you can update your master branch and merge foo-branch into master. The script for pre-push hook as below:

#!/bin/sh

git checkout master
git pull origin master
git merge foo-branch
git checkout foo-branch

注意:

  • 如果将foo-branch 合并到master 分支不是快进合并,或者合并时可能有冲突,应该使用-X选项来自动解决合并冲突.比如你可以使用 git merge foo-branch -X theirs 来代替.
  • 如果您还想将合并提交从本地 master 分支推送到远程 master 分支,您应该使用 git push --all改为 git push origin foo-branch.
  • If merging foo-branch into master branch is not fast-forward merge, or there may has conflicts when merging, you should use -X option to resolve merge conflicts automatically. Such as you can use git merge foo-branch -X theirs to instead.
  • If you also want to push the merge commit from local master branch to remote master branch, you should use git push --all to instead git push origin foo-branch.

顺便说一句:即使您在将更改推送到远程仓库时使用 webhook 触发脚本,您仍然无法从远程仓库执行 git fetch 和 git merge.

BTW: Even you use webhook to trigger a script when changes pushed to remote repo, you still can't execute git fetch and git merge from remote repo.

这篇关于如何自动更新我的远程仓库的服务器副本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆