git hook post-receive后如何同步stage(index)和工作目录? [英] How to sync the stage(index) and working directory after git hook post-receive?

查看:78
本文介绍了git hook post-receive后如何同步stage(index)和工作目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的另一个问题中,

In my other question, Issue in automatic executing post-commit in git hook to sync local and remote directory, I could use git hook to invoke post-receive so that the working directory is the same as git bare repository.

unset GIT_INDEX_FILE
git --work-tree=/home/ubuntu/dumb --git-dir=/home/ubuntu/git/dumb.git checkout -f

在推送之后,工作目录被修改,但是索引未更新. 例如,在我的本地计算机上,添加一行"???".在hello.txt中.我添加/提交/推送更改以自动更新服务器工作git目录中的hello.txt.

After the push the working directory is revised, but the index is not updated. For example, in my local machine, I add a line "???" in hello.txt. I added/commited/push the change to automatically update the hello.txt in server's working git directory.

diff --git a/hello.txt b/hello.txt
index 3ab3c7a..b63ad40 100644
--- a/hello.txt
+++ b/hello.txt
@@ -4,3 +4,5 @@ Again, helloooo, world?
 Hello, world? Automatically?

 How about this?
+
+????

我尝试从服务器的工作目录添加/提交/推送以获取此错误.

I tried add/commit/push from the server's working directory to get this error.

ubuntu@ip-172-31-63-19 dumb> git push
To /home/ubuntu/git/dumb.git/
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to '/home/ubuntu/git/dumb.git/'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

可能是什么问题?如何同步阶段(索引)和工作目录?

What might be wrong? How to sync the stage(index) and working directory?

参考:来自>"git reset"和"git reset"之间有什么区别?和"git checkout"?,我可以在工作目录中运行git reset --hard进行同步,但推送的更改将被覆盖.然后,使用git push,我可以获得更新的版本,但是我需要合并.

From What's the difference between "git reset" and "git checkout"?, I could run git reset --hard in the working directory to make the sync, but the changes pushed are overwritten. Then, with git push, I could get the updated version, but I needed a merge.

这是服务器工作目录中的git log --pretty=oneline.

This is a git log --pretty=oneline from server's working directory.

86461a03f7d46bbc90d1ef47ae3a21774848407f Merge branch 'master' of /home/ubuntu/git/dumb
049111edb0e612ec3bf364ea01423cdea8575560 1234
f506be37c3cd6d24ec727ebfb551c9d5dbd780b5 ?*
ca5a0f5efb90788c3e1669d192d3fb333fdbcd72 ?

这是来自本地目录

049111edb0e612ec3bf364ea01423cdea8575560 1234
f506be37c3cd6d24ec727ebfb551c9d5dbd780b5 ?*
ca5a0f5efb90788c3e1669d192d3fb333fdbcd72 ?

推荐答案

问题是,即使工作目录包含服务器的最新更新,本地git目录中的索引和历史记录也不会更新.

The issue is that even though the working directory contains the server's newest update, the index and history in the local git directory is not updated.

我认为这不是最好的解决方案,但是在服务器的工作目录中,我可以同步到最新更新.

I don't think this is the best solution, but in the server's working directory, I could sync to the latest update.

  1. git stash
  2. git pull
  3. git藏匿点

它会将更改存储在工作目录和索引/历史记录中,以防止发生冲突,然后拉动进行同步并丢弃该存储.现在,我可以自动从本地目录同步到服务器的工作目录,并且可以不时更新更改.

It stashes the changes in the working directory and index/history in order to prevent the collision, then pull to sync and throw away the stash. For now, I can automatically sync from my local directory to server's working directory, and I can update the change from time to time.

尽管我希望有一个完整的解决方案,而不是这个临时的解决方案.

Though I expect a full solution, not this temporary solution.

这篇关于git hook post-receive后如何同步stage(index)和工作目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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