Local git repo force updated from a remote git repo. (thick-client deployments)

隐身守侯 提交于 2019-12-19 10:17:03

问题


Update: I think this is related to an issue with the windows git client msysgit. Sorry to trouble you guys. http://code.google.com/p/msysgit/issues/detail?id=379&colspec=ID%20Type%20Status%20Priority%20Component%20Owner%20Summary

I'm looking for a way to keep several client boxes in synch with a remote git repo. Forcing updates from the remote repo and abandoning anything that may have changed on the client boxes.

The problem I'm running into is that the client boxes will modify some of the files (installation logs etc.) and gives me a merge nightmare when I need to update them from the remote repo. I've tried several commands to try and reset their local changes (the local changes should just be abandoned), but none seem to be working as advertised (git reset --hard).

I don't want to do a clone and then delete the .git dir on these boxes as I'd prefer them to only update with changes rather than pulling down the entire repo every time.

Any ideas?


回答1:


I'm assuming you have a good reason for using Git for this, rather than rsync.

This is how I'd do it (on the Clients):

git fetch origin
git reset --hard origin/master
git clean -dfx

Note that you need to reset to origin/master rather than HEAD because the local HEAD doesn't include the origin's newest commits (yet).




回答2:


It sounds like you are looking for rsync, not git. Can you explain a bit more why you would want to use a full revision control system to "merely" keep some files in sync?




回答3:


The following two commands should reset the client's working tree to a clean state, i.e. identical to how it was following the preceding git clone:

git reset --hard HEAD

This will undo any modifications made to files which are tracked (i.e. which exist in the repo).

git clean -fdx

This will remove any files which have been newly created by the client, i.e. which are not tracked by git.




回答4:


It's strange, git reset --hard should remove any change made in the local repositories.

you can try git stash && git pull, it just move the changes in some kind of temporay branch (git stash clear to remove any trace of the changes)

if that does not work, you can try this (assuming you are on the master branch and that the tmp branch does not exists)

git checkout origin/master -b tmp
git branch -D master
git branch -m master



回答5:


For the record, this original issue seems to be limited to msysgit 1.6.5.1 (issue 379), as mentioned by the OP.

However, that same issue mentions in 2012 a similar problem with other causes:

For the record, I have this issue with autocrlf = false.

Performing a git reset --hard still leaves uncommitted changes relating to file permissions:

$ git reset --hard
HEAD is now at 088c702 BranchA

$ git diff

diff --git a/path/to/file b/path/to/file
old mode 100755
new mode 100644
...

This is in relation with "Removing files saying “old mode 100755 new mode 100644” from unstaged changes in git"

I've discovered that for some reason, core.filemode was set to true on repository level (I didn't set it myself):

$ cat .git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true

So: git config core.filemode false is recommended.



来源:https://stackoverflow.com/questions/2290836/local-git-repo-force-updated-from-a-remote-git-repo-thick-client-deployments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!