简体   繁体   English

如何在无业游民的VM中使用cygwin,git bash和git在Windows上设置git?

[英]How to setup git on windows with cygwin, git bash and git in a vagrant VM?

My Setup 我的设定

We are using Windows 10 at work. 我们正在使用Windows 10。 I had the task to build a development VM with Vagrant which we all want to use. 我的任务是使用我们都想使用的Vagrant构建开发VM。

We are mounting our git folders into the VM via the Vagrant SSH mount which works perfect for now. 我们正在通过Vagrant SSH挂载将git文件夹挂载到VM中,该挂载目前非常完美。

We are also using Visual Studio Code as Editor. 我们还将Visual Studio Code用作编辑器。

My Goal 我的目标

I want to use git in cygwin (for the windows users) and git in the VM seamlessly. 我想在cygwin中(对于Windows用户)使用git,并在VM中无缝使用git。

And of course we want to use the feature of Visual studio code to hightlight the changed files. 当然,我们希望使用Visual Studio代码的功能来突出显示已更改的文件。 As I understand it right Visual Studio Code is using the git implementation from the git bash. 据我了解,Visual Studio Code是使用git bash中的git实现。 But this is a secondary requirement. 但这是次要条件。

My config 我的配置

On all machine I have the following .gitconfig : 在所有机器上,我都有以下.gitconfig

[core]
    autocrlf = input
    editor = vim
    eol = lf
    filemode = false

My Problem 我的问题

I clone a repo and the shells show me differnt outputs 我克隆了一个回购协议,而sh​​ell向我展示了不同的输出

git bash : git bash

pwd
/c/Users/user/git/docker-install
>git status
On branch master
Your branch is up to date with 'origin/master'.

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:   .gitattributes

no changes added to commit (use "git add" and/or "git commit -a")
>git diff
diff --git a/.gitattributes b/.gitattributes
old mode 100755
new mode 100644

cygwin : cygwin

user@machine /cygdrive/c/Users/user/git/docker-install
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

user@machine /cygdrive/c/Users/user/git/docker-install
$ git diff

user@machine /cygdrive/c/Users/user/git/docker-install
$

Git vagrant VM : Git流浪者VM

[vagrant@vagrant docker-install (⎈ |minikube:default)]$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
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:   .gitattributes

no changes added to commit (use "git add" and/or "git commit -a")
[vagrant@vagrant docker-install (⎈ |minikube:default)]$ git diff
diff --git a/.gitattributes b/.gitattributes
old mode 100755
new mode 100644
[vagrant@vagrant docker-install (⎈ |minikube:default)]$

My .gitattributes in this this repo 我的.gitattributes在此仓库中

* text=auto

How should I setup my gitconfigs? 我应该如何设置我的gitconfigs?

I read a lot of articles, spend a lot of time but I am still confused how we should setup our environment. 我读了很多文章,花了很多时间,但是我仍然对如何设置环境感到困惑。

Can someone help me on this one? 有人可以帮我吗?

First, Cygwin is not the only option: WSL (Windows Subsystem for Linux) is another option which would offer a true Linux-like experience. 首先,Cygwin不是唯一的选择: WSL(Linux的Windows子系统)是另一个选择,它将提供真正的类似于Linux的体验。

Second, as noted, git config --global core.fileMode false is needed in Vagrant to ignore chmod. 其次,如前所述,在Vagrant中需要git config --global core.fileMode false来忽略chmod。

But third, for files you know you want to be recorded with +x (755 instead of 644), irrespective of the OS ( like in Windows , which would ignore the execute permission), type ( with Git 2.9.1+ ): 但是第三,对于您知道要用+ x(755而不是644)记录的文件,而不考虑操作系统( 例如Windows ,它将忽略执行权限),键入( 使用Git 2.9.1+ ):

git add --chmod=+x -- afile

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

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