4

git diff shows the correct indentation, but git add -p does not. Here's are how the same changes are represented.

$ git diff
diff --git a/utils/utils.go b/utils/utils.go
index 3796954..b755bd5 100644
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -11,7 +11,7 @@ import (
 )

 func LogsDir(homeDir string) string {
-       return filepath.Join(homeDir, "logs")
+       return filepath.Join(homeDirs, "logs")
 }
$ git add -p
diff --git a/utils/utils.go b/utils/utils.go
index 3796954..b755bd5 100644
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -11,7 +11,7 @@ import (
 )

 func LogsDir(homeDir string) string {
-   return filepath.Join(homeDir, "logs")
+ return filepath.Join(homeDirs, "logs")
 }

(1/1) Stage this hunk [y,n,q,a,d,e,?]?

What's wrong with my configuration?

mango
  • 5,577
  • 4
  • 29
  • 41
  • Are you using tabs to indent, maybe? – Hasturkun Aug 08 '21 at 08:45
  • @Hasturkun That's a good callout and could very well be the issue. Is there a way to show tabs appropriately though? This code is golang, and its formatter rewrites the code with like so. – mango Aug 08 '21 at 10:01
  • 2
    Possibly, nothing is wrong with your configuration. Or perhaps you have tab expansion set in an unusual manner. The `gofmt` formatter does use tabs, which it expects your terminal to have at every eighth column. I'd expect that to show up the same either way though. – torek Aug 08 '21 at 11:29
  • (idea taken from another question) : the pager might get in the way and format the output with rules of its own. If you still have some file that exhibits the issue, try disabling the pager : `git --no-pager diff -- that/file.go` ; inspect more closely the content of the file (its content before and after) to see if there is a combination of space and tabs a the beginning of that line. – LeGEC Sep 03 '21 at 12:02
  • 1
    the other question : https://stackoverflow.com/questions/69040986/why-does-git-diff-and-git-show-seem-to-replace-tabs-with-spaces – LeGEC Sep 03 '21 at 12:04

1 Answers1

0

The output of git diff may go through the pager (if git detect that it is longer than one screen ...), and the pager may introduce some formatting of its own before printing on the terminal.

Try running git diff | cat or git --no-pager diff to see if you still have the same output.

Do also check the content of the versioned file (git show HEAD:utils/utils.go > /tmp/utils.go) and the current content of that file on your disk.

LeGEC
  • 46,477
  • 5
  • 57
  • 104