为什么我的git origin要删除所有推送的更改?

时间:2010-08-19 18:00:18

标签: git dvcs

在认为我终于想出了git之后,我现在发现自己对我所看到的git行为非常困惑 - 每当我推动所做的更改并将其提交到我的本地机器到我的原始git存储库时,那些更改会立即在原始服务器上暂停。咦?!?

我有一台机器(机器A),上面有一个项目的git存储库;该机器正在运行SSH服务器,我配置了一个帐户,以便我可以远程连接它并克隆git repo。然后我在机器B上使用git克隆了回购:

git clone ssh://username@remote.host/path/to/repo

没有问题。我在机器B上对项目进行了更改,并将这些更改提交到B上的git存储库。然后,我将更改推送回机器A上的源存储库:

git push master origin

并且工作正常;在机器B上,git remote show origin的输出显示原点是最新的:

$ git remote show origin
* remote origin
  Fetch URL: ssh://username@remote.host/path/to/repo
  Push  URL: ssh://username@remote.host/path/to/repo
  HEAD branch: master
  Remote branch:
    master tracked
  Local ref configured for 'git push':
    master pushes to master (up to date)

但是当我去机器A并做git status时,我发现我刚刚推动的所有变化现在都被撤消了!

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   build-fatjar.xml
#       deleted:    src/monitor/config/client-lm-prod.xml
#       modified:   src/monitor/config/quartz-baseconfig.xml
#       modified:   src/monitor/service/task/BaseTask.java
#       new file:   src/monitor/service/task/CheckForCorrections.java
#       deleted:    src/monitor/service/task/CheckForDuplicates.java
#       deleted:    src/monitor/service/task/ProcessCorrections.java
#       renamed:    src/monitor/test/CheckForDuplicatesTest.java -> src/monitor/test/CheckForCorrectionsTest.java
#       deleted:    src/monitor/test/ProcessCorrectionsTest.java
#       modified:   src/monitor/test/TaskTestCase.java

将原始存储库(计算机A)置于与计算机B上的状态相同的状态的唯一方法是git reset HEAD重置所有要提交的更改,然后git rm他们每个人;否则,机器A上的下一个git commit将撤消我刚刚从机器B推送的所有内容。

我已经读过每一个我可以得到的参考文献而且没有提到这种行为;同样,我也无法在网上找到它的参考。有什么想法吗?

2 个答案:

答案 0 :(得分:5)

听起来你正在推动一个非裸仓库(即一个在磁盘上签出文件的仓库)。 Git会更新回购,但签出的文件,所以看起来有等待上传的变化。解决方法是做两件事之一:

  1. 要么推入一个裸仓库(原产地),然后使用后接收挂钩检查文件(可能使用git archive)到服务器上的另一个地方,或者
  2. 使用post-receive挂钩运行git checkout或某些更新磁盘文件。
  3. 您可以在此Stack Overflow question或此how-to article中阅读更多内容。

答案 1 :(得分:0)

是的@MvanGeest是对的,你正在推动一个非裸的回购。如果你打算将repo用作'blessed repo',就像你在subversion中使用master存储库一样,那么你需要创建一个裸存储库并推送到它。如果在你现在的情况下,你必须ssh到a并从b拉。