6

I have a git repo in my system.
When I enter git status using windows PowerShell, I get a result and when I enter it in the windows bash, I get a different result.

See the image for more details.

enter image description here

As you can see git status in windows PowerShell says Nothing to commit, while same git status in windows bash says you have unstaged changes.

Here is an output result of git version in both:
Windows powershell: git version 2.18.0.windows.1
Windows bash: git version 2.7.4

And here's a git diff .idea/gradle.xml:
Powershell:
Bash:

diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 7ac24c7..15dda04 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -1,18 +1,18 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="GradleSettings">
-    <option name="linkedExternalProjectsSettings">
-      <GradleProjectSettings>
-        <option name="distributionType" value="DEFAULT_WRAPPED" />
-        <option name="externalProjectPath" value="$PROJECT_DIR$" />
-        <option name="modules">
-          <set>
-            <option value="$PROJECT_DIR$" />
-            <option value="$PROJECT_DIR$/app" />
-          </set>
-        </option>
-        <option name="resolveModulePerSourceSet" value="false" />
-      </GradleProjectSettings>
-    </option>
-  </component>
+<?xml version="1.0" encoding="UTF-8"?>^M
+<project version="4">^M
+  <component name="GradleSettings">^M
+    <option name="linkedExternalProjectsSettings">^M
+      <GradleProjectSettings>^M
+        <option name="distributionType" value="DEFAULT_WRAPPED" />^M
+        <option name="externalProjectPath" value="$PROJECT_DIR$" />^M
+        <option name="modules">^M
+          <set>^M
+            <option value="$PROJECT_DIR$" />^M
+            <option value="$PROJECT_DIR$/app" />^M
+          </set>^M
+        </option>^M
+        <option name="resolveModulePerSourceSet" value="false" />^M
+      </GradleProjectSettings>^M
+    </option>^M
+  </component>^M
 </project>
\ No newline at end of file
:
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 7ac24c7..15dda04 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -1,18 +1,18 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="GradleSettings">
-    <option name="linkedExternalProjectsSettings">
-      <GradleProjectSettings>
-        <option name="distributionType" value="DEFAULT_WRAPPED" />
-        <option name="externalProjectPath" value="$PROJECT_DIR$" />
-        <option name="modules">
-          <set>
-            <option value="$PROJECT_DIR$" />
-            <option value="$PROJECT_DIR$/app" />
-          </set>
-        </option>
-        <option name="resolveModulePerSourceSet" value="false" />
-      </GradleProjectSettings>
-    </option>
-  </component>
+<?xml version="1.0" encoding="UTF-8"?>^M
+<project version="4">^M
+  <component name="GradleSettings">^M
+    <option name="linkedExternalProjectsSettings">^M
+      <GradleProjectSettings>^M
+        <option name="distributionType" value="DEFAULT_WRAPPED" />^M
+        <option name="externalProjectPath" value="$PROJECT_DIR$" />^M
+        <option name="modules">^M
+          <set>^M
+            <option value="$PROJECT_DIR$" />^M
+            <option value="$PROJECT_DIR$/app" />^M
+          </set>^M
+        </option>^M
+        <option name="resolveModulePerSourceSet" value="false" />^M
+      </GradleProjectSettings>^M
+    </option>^M
+  </component>^M
 </project>
\ No newline at end of file
:...skipping...
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 7ac24c7..15dda04 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -1,18 +1,18 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="GradleSettings">
-    <option name="linkedExternalProjectsSettings">
-      <GradleProjectSettings>
-        <option name="distributionType" value="DEFAULT_WRAPPED" />
-        <option name="externalProjectPath" value="$PROJECT_DIR$" />
-        <option name="modules">
-          <set>
-            <option value="$PROJECT_DIR$" />
-            <option value="$PROJECT_DIR$/app" />
-          </set>
-        </option>
-        <option name="resolveModulePerSourceSet" value="false" />
-      </GradleProjectSettings>
-    </option>
-  </component>
+<?xml version="1.0" encoding="UTF-8"?>^M
+<project version="4">^M
+  <component name="GradleSettings">^M
+    <option name="linkedExternalProjectsSettings">^M
+      <GradleProjectSettings>^M
+        <option name="distributionType" value="DEFAULT_WRAPPED" />^M
+        <option name="externalProjectPath" value="$PROJECT_DIR$" />^M
+        <option name="modules">^M
+          <set>^M
+            <option value="$PROJECT_DIR$" />^M
+            <option value="$PROJECT_DIR$/app" />^M
+          </set>^M
+        </option>^M
+        <option name="resolveModulePerSourceSet" value="false" />^M
+      </GradleProjectSettings>^M
+    </option>^M
+  </component>^M
 </project>
\ No newline at end of file
~

As you can see it's completely different.

Here's the output of git config -l: Powershell:

core.symlinks=true
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
rebase.autosquash=true
http.sslcainfo=D:/Apps/Git/mingw64/ssl/certs/ca-bundle.crt
http.sslbackend=openssl
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
credential.helper=manager
user.name=Mahdi
user.email=mahdi.malvandi@pushe.co
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
remote.origin.url=git@github.com:mahdi-malv/shahpari_market.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.setMainActivity.remote=origin
branch.setMainActivity.merge=refs/heads/setMainActivity
branch.networkSetup.remote=origin
branch.networkSetup.merge=refs/heads/networkSetup
branch.compNav.remote=origin
branch.compNav.merge=refs/heads/compNav
branch.presenter.remote=origin
branch.presenter.merge=refs/heads/presenter
branch.mainUi.remote=origin
branch.mainUi.merge=refs/heads/mainUi
branch.downloadManager.remote=origin
branch.downloadManager.merge=refs/heads/downloadManager
branch.category.remote=origin
branch.category.merge=refs/heads/category
:

Bash:

core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
remote.origin.url=git@github.com:mahdi-malv/shahpari_market.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.setMainActivity.remote=origin
branch.setMainActivity.merge=refs/heads/setMainActivity
branch.networkSetup.remote=origin
branch.networkSetup.merge=refs/heads/networkSetup
branch.compNav.remote=origin
branch.compNav.merge=refs/heads/compNav
branch.presenter.remote=origin
branch.presenter.merge=refs/heads/presenter
branch.mainUi.remote=origin
branch.mainUi.merge=refs/heads/mainUi
branch.downloadManager.remote=origin
branch.downloadManager.merge=refs/heads/downloadManager
branch.category.remote=origin
branch.category.merge=refs/heads/category
branch.setCategory.remote=origin
branch.setCategory.merge=refs/heads/setCategory
branch.searchFix.remote=origin
branch.searchFix.merge=refs/heads/searchFix
branch.homeMoreAPI.remote=origin
branch.homeMoreAPI.merge=refs/heads/homeMoreAPI
branch.userApp.remote=origin
branch.userApp.merge=refs/heads/userApp
branch.allApps.remote=origin
branch.allApps.merge=refs/heads/allApps
branch.settings.remote=origin
branch.settings.merge=refs/heads/settings
branch.autoUpdate.remote=origin
branch.autoUpdate.merge=refs/heads/autoUpdate
branch.tempStore.remote=origin
branch.tempStore.merge=refs/heads/tempStore
branch.fixIcon.remote=origin
branch.fixIcon.merge=refs/heads/fixIcon
branch.changeAd.remote=origin
branch.changeAd.merge=refs/heads/changeAd
branch.updateAndAnal.remote=origin
branch.updateAndAnal.merge=refs/heads/updateAndAnal
branch.merge1.remote=origin
branch.merge1.merge=refs/heads/merge1
branch.fixV1beta.remote=origin
branch.fixV1beta.merge=refs/heads/fixV1beta
branch.sendDevice.remote=origin
branch.sendDevice.merge=refs/heads/sendDevice
branch.newIcon.remote=origin
branch.newIcon.merge=refs/heads/newIcon

What is causing this issue and how i can fix it?

Thanks in advance.

Note:
In addition to the accepted answer and by considering Ralf's answer, I found that making both shells use one git is a good idea.
- Remove Git from bash using sudo apt remove git.
- Add path of git.exe in $PATH of bash.
- For simplicity use alias git='git.exe' to be able to use Git like before.

You can do this for other things that might face this problem like python and so on.

Mahdi-Malv
  • 16,677
  • 10
  • 70
  • 117
  • I've seen this problem show up when using git from 'git for windows' and then 'git through cygwin'. I guess that the problem is how both binaries get to see the execution flag of the files. What is the output of `git diff .idea/gradle.xml`? Also, what is the output of `git version` for both _environments_? Can you add the output of both to the original question? – eftshift0 Feb 07 '19 at 05:16
  • @TimBiegeleisen what??? `git version` and `git diff .idea/gradle.xml`? Where? – eftshift0 Feb 07 '19 at 05:20
  • Oh...didn't see `diff` in there, yes, that would be good to see as well. – Tim Biegeleisen Feb 07 '19 at 05:21
  • @eftshift0 Interesting. For windows `git version` returns: `git version 2.18.0.windows.1`. And for `windows bash` it will be `git version 2.7.4` – Mahdi-Malv Feb 07 '19 at 05:21
  • `git diff` for `gradle.xml` is empty for `windows powershell`, while it's having all differences in `bash` – Mahdi-Malv Feb 07 '19 at 05:23
  • What about diff? I bet the problem is related to the +x flag of the files (though it might be something related to configs, like one git is using auto.crlf and the other is not? All kinds of crazy things can happen). Maybe also checking `git config -l`for both could help a little bit, – eftshift0 Feb 07 '19 at 05:23
  • What do you mean with `all differences`? Like the file is completely removed and replaced with the same content? – eftshift0 Feb 07 '19 at 05:24
  • First: Which one is right? The file `.idea/gradle.xml` looks like a file that should normaly be ignored. Could it be that `.gitignore` uses CRLF line endings and the git in bash is unable to understand it? – Ralf Feb 07 '19 at 05:25
  • By the way, all these outputs should be added to the original question. – eftshift0 Feb 07 '19 at 05:25
  • @Ralf: It doesn't matter. The outputs shouldn't differ, should they? – eftshift0 Feb 07 '19 at 05:26
  • No the outputs can't differ. – Mahdi-Malv Feb 07 '19 at 05:28
  • @Malv.... They _could_ differ. We are trying to understand why they do so that it can be avoided. – eftshift0 Feb 07 '19 at 05:29
  • Can you try this? Add this to .gitattributes: `* -text` and then try `git status` again on both. Then you can take it out. – eftshift0 Feb 07 '19 at 05:30
  • If it solves the problem, it's because the configuration of auto.crlf (or something like that) is different between both gits. By using `* -text`on .gitattributes, you are telling git to avoid any EOL conversion and handle the files "as is". – eftshift0 Feb 07 '19 at 05:31
  • And then I'll write it as an answer and @Malv will upvote it and check it as _the answer_, right? – eftshift0 Feb 07 '19 at 05:33
  • @eftshift0 Nope. adding `* -text` didn't make a difference, other than both say `.gitattributes` is created – Mahdi-Malv Feb 07 '19 at 05:34
  • :( What is the output of `git config -l` on both? That should be added to the original question. – eftshift0 Feb 07 '19 at 05:35
  • The value of auto.crlf is different between both. I guess that's set globally. Can you set it on the repo? – eftshift0 Feb 07 '19 at 05:38
  • But that's exactly what we tried to do (override this value) by using .gitattributes. Perhaps the files have been already modified on the working tree by one of the two gits? Can you check this as well? `file .idea/gradle.xml` on both environments, also `git show HEAD:.idea/gradle.xml | file -`. We might discover that the file has already changed its EOL format already on the working tree. – eftshift0 Feb 07 '19 at 05:41

3 Answers3

2

In addition of having two different version of Git, you should check the configs in both session, with:

git config -l --show-origin

That may show not only different configs, but different config files (like when HOME differs between both, or when the system config differs between separate Git installations)

In your setup, the presence of core.autocrlf=true in the second settings explains the git diff output.
Make sure to type: git config --global core.autocrlf false in both shell.

In any case, try using a simplified PATH (with a PortableGit-2.20.1-64-bit.7z.exe Git uncompressed anywhere you want), and then call git bash within that CMD with said simplified PATH: the result should then be the same.

set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%
torek
  • 448,244
  • 59
  • 642
  • 775
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

Long story short: core.autocrlf is different in both environments. That explains why on powershell it's telling you that the files are completely different (removing all the content and adding it exactly the same again.... because it's changing the EOL of those lines). The way to avoid it from happening is by using this on .gitattributes: * -text. If by doing this the problem remains, it's probably because the file has already changed its EOL format on the working tree. Try switching it back to what it was on HEAD and then the file should disappear from git status.

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • By comparing output of existing and changed in `git diff` command, you'll see only `^M` is the difference between. So by ignoring it using `.gitattributes` and `* -text` it solved the problem. – Mahdi-Malv Feb 07 '19 at 05:57
  • And also didn't work at first, 'cause it was already modified. So switching back to HEAD helped it. Thanks for the help. – Mahdi-Malv Feb 07 '19 at 05:59
2

While the accepted answer shows how to fix that problem, I would give another advice:

Either use git on Powershell or git on Bash. Don't mix when managing the same working copy.

Update:

It is (most likely) ok to use git on Powershell and other Windows-based git tools (you mentioned gitKraken and and Android Studio in the comment).

My understanding is that bash and git on Bash comes from the Windows Subsystem for Linux. So they will assume a different EOL styles.

Ralf
  • 1,773
  • 8
  • 17
  • I use `gitKraken` and sometimes `Android studio's git`. I guess they use git of windows. So if i use `git` in the bash, that would be a mix. Updating both gits or using a portable git should solve the problem, right? – Mahdi-Malv Feb 07 '19 at 06:07
  • @Malv I don't know. – Ralf Feb 07 '19 at 06:28