Reputation: 19278
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.
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
[email protected]
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
[email protected]: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
[email protected]: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.
Upvotes: 6
Views: 1367
Reputation: 1813
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.
Upvotes: 2
Reputation: 1329722
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%
Upvotes: 2
Reputation: 30317
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.
Upvotes: 2