3

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?
4

1 回答 1

2

如果您的推送(到非裸)回购成功,那是因为:

  • 要么您推送了一个未在远程仓库中签出的分支(非裸远程仓库)
  • 或被receive.denyCurrentBranch设置为falseignoregit config

在后一种情况下,任何当前的本地修改都不会被该推送删除。
只有 agit checkout --force会将工作目录重置为HEAD.

确保两个非裸仓库之间同步的常用方法是添加一个中间裸仓库(您推送到该仓库)和一个 post-receive 挂钩,该挂钩将进入实际的远程仓库(非裸仓库)并更新的裸回购。
常见的例子:使用 Git 管理网站,我用在:

拉动时,请确保取消设置GIT_DIR:请参阅“从 git挂钩调用 'git pullpost-update ' ”

于 2012-07-21T15:03:37.057 回答