【问题标题】:Git pull leaving pulled files in a weird stateGit pull 使拉取的文件处于奇怪的状态
【发布时间】:2013-08-28 06:33:35
【问题描述】:

我遇到了一个非常奇怪的 git 问题。我有一个 ruby​​ 应用程序在运行在 runit 管理下的服务器上。此应用程序具有自动更新功能。 它执行git ls-remote 来检查是否需要拉取和服务重启。这部分工作正常,执行内容并拉取文件,但是:拉取之后,所有拉取的更改都保留在 "changes not staged for commit" 中。执行git reset --hard 后,repo 没有为提交准备任何更改,但 repo 的本地副本显示它比 origin/branch 提前 X 次提交。

我不确定为什么会发生这种情况以及如何解决问题。有没有人经历过类似的事情?任何指针表示赞赏。

为了简单起见,软件在 Ubuntu 12.04、ruby 1.9.3p448 上运行(以 root 身份运行的 runit)。文件具有正确的权限,至少看起来是这样。

代码可以看这里:https://github.com/radekg/rgossip_app/blob/dev/lib/updater.rb git pullgit fetchgit reset 都不起作用。

*更新:*

git status 返回:

root@ip-10-222-29-69:/opt/rgossip# git status
# On branch dev
# Your branch is ahead of 'origin/dev' by 1 commit.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   README.md
#
no changes added to commit (use "git add" and/or "git commit -a")

git diff:

root@ip-10-222-29-69:/opt/rgossip# git diff
diff --git a/README.md b/README.md
index e7136db..e9d7360 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,3 @@
 Managing Chef boxes with gossip.

-More description soon. Testing.
\ No newline at end of file
+More description soon.
\ No newline at end of file

这就是这次提交:https://github.com/radekg/rgossip_app/commit/176e7cf764ff9ea0299ef75a21bb79a5bea11406

执行git reset --hard后我得到:

root@ip-10-222-29-69:/opt/rgossip# git reset --hard
HEAD is now at 176e7cf Testing with commits seems stupid.

【问题讨论】:

  • git status 准确地说出什么? git diff 说明了什么?
  • 我已经用这些信息更新了我的问题。
  • 我围绕这个做了一些测试。只有当我将--git-dir 与拉动一起使用时,问题似乎才会发生。我将尝试复制此问题并发布我的发现。

标签: ruby git ubuntu-12.04 runit


【解决方案1】:

git pull 基本上是 git fetch 后跟 git merge。如果您已完成合并,您将领先于原点/分支,因为原点/分支上不存在该合并。

你真的不应该在自动脚本中使用合并,这是一个可能需要人工交互的命令,你应该使用 git fetch 和 git checkout。

【讨论】:

  • 但这也有点奇怪:root@ip-10-222-29-69:/opt/rgossip# git status# On branch dev# Your branch is ahead of 'origin/dev' by 2 commits.#nothing to commit (working directory clean)root@ip-10-222-29-69:/opt/rgossip# git push origin devEverything up-to-date
猜你喜欢
  • 1970-01-01
  • 2020-12-30
  • 1970-01-01
  • 2014-02-10
  • 2015-12-03
  • 2020-05-24
  • 1970-01-01
  • 1970-01-01
  • 2022-07-23
相关资源
最近更新 更多