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

僤鯓⒐⒋嵵緔 提交于 2019-12-01 10:46:47

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).

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?

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.

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
VonC

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.

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