为什么我需要强制git同步我的远程存储库? [英] Why do I need to force git to sync my remote repository?

查看:105
本文介绍了为什么我需要强制git同步我的远程存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地存储库,我从远程存储库中克隆(全部在一台机器上)。我想确保我的远程存储库从我的本地存储库中选择了更改,所以我做了一个 git push origin



我将工作目录更改为远程存储库;更改已传播到日志文件中(即,执行 git log 显示更改),但我的实际工作目录未显示更改。我做了一个 git checkout HEAD ,但CWD仍然没有改变。直到我做了一个 git checkout --force HEAD ,CWD同步了。



我怀疑这是因为远程存储库不是裸存储库。所以有两个问题:


  1. 是否有一种方法可以使远程存储库自动同步(即放弃本地更改)在 git push

  2. 为什么我需要使用 --force 来获取它同步?什么应该是同步它的过程?


解决方案

如果你的push(非裸)回购成功,这是因为:


  • 或者你推送了一个未检出的分支你的远程仓库(非裸露的远程仓库)

  • receive.denyCurrentBranch 被设置为 false 或忽略 git config



在后一种情况下,任何当前的本地修改不会被该推送删除。

只有一个 git checkout --force 会将工作目录重置为引用的实际索引内容通过 HEAD



确保两个非裸回购的同步方式通常是通过添加一个中间裸回购(你推)与一个后接收钩将去实际的远程回购(非巴并且从更新后的裸露回购库中 pull

通常的例子:



当您拉动时,请确保取消设置 GIT_DIR :参见卡尔从$ git 更新后钩子 $ git pull b

I have a local repository that I've cloned from my remote repository (all on one machine). I wanted to make sure that my remote repository picked the changes from my local repository so I did a git push origin.

I changed my working directory to my remote repository; the change had propagated to the log file (i.e. doing git log showed the change) but my actual working directory didn't show the change. I did a git checkout HEAD but the CWD still didn't change. It wasn't until I did a git checkout --force HEAD that the CWD synced up.

I suspect this is happening because the remote repository isn't a bare repository. So two questions:

  1. Is there a way that I can make the remote repository automatically sync (i.e. discard local changes) on a git push?
  2. Why do I need to to use --force to get it to sync up? What should be the process of syncing it up?

解决方案

If your push (to a non-bare) repo succeeded, it is because:

  • either you pushed a branch which wasn't checked out on your remote repo (the non-bare remote repo)
  • or receive.denyCurrentBranch was set to false or ignore in the git config

In the latter case, any current local modification wouldn't be erased by that push.
Only a git checkout --force would reset the working directory to the actual index content referenced by HEAD.

The usual way to ensure synchronization between two non-bare repo is by adding an intermediate bare repo (to which you push) with a post-receive hook which will go the actual remote repo (the non-bare one) and pull from the updated bare repo.
The usual example: Using Git to manage a web site, which I use in:

When you are pulling, make sure to unset GIT_DIR: see "Calling 'git pull' from a git post-update hook"

这篇关于为什么我需要强制git同步我的远程存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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