简体   繁体   English

Git pull挂在SMB共享存储库上

[英]Git pull hangs on SMB shared repository

When I run git pull, I get this: 当我运行git pull时,我得到了这个:

edson$ GIT_TRACE=1 git pull -v
trace: exec: 'git-pull' '-v'
trace: run_command: 'git-pull' '-v'
trace: built-in: git 'rev-parse' '--git-dir'
trace: built-in: git 'rev-parse' '--is-bare-repository'
trace: built-in: git 'rev-parse' '--show-toplevel'
trace: built-in: git 'ls-files' '-u'
trace: built-in: git 'symbolic-ref' '-q' 'HEAD'
trace: built-in: git 'config' 'branch.master.rebase'
trace: built-in: git 'config' 'pull.rebase'
trace: built-in: git 'rev-parse' '-q' '--verify' 'HEAD'
trace: built-in: git 'fetch' '-v' '--update-head-ok'
trace: run_command: 'ssh' 'git@bitbucket.org' 'git-upload-pack '\''xxxltd/xxxltd.git'\'''
trace: run_command: 'rev-list' '--objects' '--stdin' '--not' '--all' '--quiet'
trace: run_command: 'rev-list' '--objects' '--stdin' '--not' '--all'
trace: exec: 'git' 'rev-list' '--objects' '--stdin' '--not' '--all'
trace: built-in: git 'rev-list' '--objects' '--stdin' '--not' '--all'
From bitbucket.org:xxxltd/xxx
 = [up to date]      master     -> origin/master
 = [up to date]      blah -> origin/blah
trace: run_command: 'gc' '--auto'
trace: exec: 'git' 'gc' '--auto'
trace: built-in: git 'gc' '--auto'
trace: built-in: git 'rev-parse' '-q' '--verify' 'HEAD'
trace: built-in: git 'fmt-merge-msg'

But then it just hangs there. 但那时它只是挂在那里。

The (bitbucket) repository is inside a windows 7 vmware machine. (bitbucket)存储库位于Windows 7 vmware机器中。 The repository is then shared via SMB to the host machine (mac osx). 然后,存储库通过SMB共享到主机(mac osx)。 I'm running git pull (macports) on the host. 我在主机上运行git pull(macports)。

If I run git pull (msysgit) inside the vm, it works fine. 如果我在vm中运行git pull(msysgit),它运行正常。

Any clue? 任何线索?

Apple switched to SMB2 with Mavericks and it's not working so well for quite a few people. 苹果公司转而使用小牛队转而使用SMB2,但对于不少人来说,这种方式并不是很好。 As an alternative, here's a more permanent fix you can apply instead of the temporary one of cifs:// : 作为替代方案,这里有一个更永久的修复,你可以应用而不是临时的cifs://

To force all connections to be SMB1: 强制所有连接都是SMB1:

Open A terminal window paste in the following line followed by the return key (should be all on one line): 打开以下行中的终端窗口粘贴,然后是返回键(应该全部在一行):

echo "[default]" >> ~/Library/Preferences/nsmb.conf; echo "smb_neg=smb1_only" >> ~/Library/Preferences/nsmb.conf

What the command does: 该命令的作用:

Creates a file called nsmb.conf in your home directory at the path ~/Library/Preferences/nsmb.conf . 在主目录中的〜/ Library / Preferences / nsmb.conf路径中创建一个名为nsmb.conf的文件。 Adds directives to force SMB connections to use the SMB1 protocol. 添加指令以强制SMB连接使用SMB1协议。 This is slower but stable. 这是缓慢但稳定的。

How to remove the workaround: 如何删除变通方法:

Open a terminal window paste in the following at the prompt and then hit the return button: 在提示符下打开终端窗口粘贴,然后点击返回按钮:

rm ~/Library/Preferences/nsmb.conf

Notes: ( source ) 备注:( 来源

Its a good idea to restart your mac before trying to connect to your storage again. 在尝试再次连接到存储之前重启mac是个好主意。 This will clear any hung SMB processes from previous attempts to connect to your storage before implementing this workaround. 这将清除先前尝试连接到您的存储的任何挂起的SMB进程,然后再实施此变通方法。


EDIT: Commenter replied "it wasn't helpful" — not the best choice of words, but you get the idea. 编辑:评论者回答“这没有帮助” - 不是最好的选择,但你明白了。

In the Git source, there seems to be a infinite loop in Git's fmt-merge-msg function when the repo sits in a SMB share while being accessed from Mavericks. 在Git源代码中,当来自Mavericks的repo位于SMB共享中时, Git的fmt-merge-msg函数似乎存在无限循环。 The only way I've been able to fix this is by doing doing a process that doesn't involve automatic merging. 我能够解决这个问题的唯一方法是做一个不涉及自动合并的过程。

git pull is essentially a git fetch && git merge all in one command. git pull本质上是一个git fetch && git merge all in one command。 If you try and do a git fetch into your current branch when there have been changes, you may run into an issue where the git fetch fails. 如果您在更改时尝试对当前分支执行git fetch ,则可能会遇到git fetch失败的问题。

The way that I've fixed this issue is to fetch the remote branch into a temporary local branch and them merge that temp branch into your working branch. 我修复此问题的方法是将远程分支获取到临时本地分支,然后将该临时分支合并到您的工作分支中。 See the following which details trying to fetch the latest changes from your origin/master into your current working branch master . 请参阅以下详细信息,尝试从origin/master获取最新更改到当前工作分支master

  1. Fetch the latest changes from origin master into a local branch called master_merge_tmp . origin master获取最新更改到名为master_merge_tmp的本地分支。 git fetch [<remote loc>] [<remote branch>]:[<local branch>] allows you to fetch the latest changes without invoking fmt_merge_msg automatically and you can target a different local destination branch: git fetch [<remote loc>] [<remote branch>]:[<local branch>]允许您在不调用fmt_merge_msg情况下获取最新更改,并且可以定位不同的本地目标分支:

     git fetch origin master:master_merge_tmp 
  2. Merge the master_merge_tmp branch into master : master_merge_tmp分支合并为master

     git merge master_merge_tmp 
  3. Perform some cleanup by deleting the remote branch mater_merge_tmp : 通过删除远程分支mater_merge_tmp执行一些清理:

     git branch -D master_merge_tmp 

Alternatively you could create a helper function to automate the steps above. 或者,您可以创建一个辅助函数来自动执行上述步骤。 You can place this in your .bashrc or .zshrc : 您可以将它放在.bashrc.zshrc

# Workaround for fmt-merge-msg issue on Mavericks w/SMB repo
# gfm [<remote>] [<remote branch>]
function _git-fetch-merge() {
  local remote="$1"
  local branch="$2"
  local tmp_branch="${2}_merge_tmp"
  git fetch $remote $branch:$tmp_branch
  git merge $tmp_branch
  git branch -D $tmp_branch
}
alias gfm="_git-fetch-merge"

Now from the terminal you can do the following: 现在从终端您可以执行以下操作:

_git-fetch-merge origin master

Or you can use the alias: 或者您可以使用别名:

gfm origin master

If you are working with a remote upstream branch: 如果您正在使用远程上游分支:

gfm upstream master

Mavericks has known issues with the SMB protocol. 小牛队已经知道SMB协议的问题。 Try mounting the repo as cifs://vm.ip instead of smb://vm.ip (source) . 尝试将repo安装为cifs://vm.ip而不是smb://vm.ip (source)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM