List only the added files and modes in the git cast

Asked

Viewed 58 times

2

I’m having trouble dealing with file permissions in git. In this case, I need to check if the file has been added with the correct permission mode. As for changing the permissions mode, you already have a question on the subject. But now I need to confirm that the file is in the correct mode.

In the quoted question, the file was already added in the repository, so the git diff returned only that the permission was changed. Now, however, the file to be added needs to enter specific mode.

When validating with gif diff, shows me all the changes. For example:

$ git diff HEAD
diff --git a/numobile/android/gradlew b/numobile/android/gradlew
new file mode 100755
index 0000000000..9d82f78915
--- /dev/null
+++ b/numobile/android/gradlew
@@ -0,0 +1,160 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
    [ 149 linhas omitidas ... ]
diff --git a/numobile/android/gradlew.bat b/numobile/android/gradlew.bat
new file mode 100644
index 0000000000..aec99730b4
--- /dev/null
+++ b/numobile/android/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem  Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
    [ 81 linhas omitidas... ]

Currently the modes are correct, the way I wanted for these 2 files in particular. But I wish I could list the listed files and their permissions without having to browse through the entire file added.

For example, showing the file and its permissions (it doesn’t have to be literally like this, it’s just an example: path and permissions):

new file numobile/android/gradlew mode 100755 
new file numobile/android/gradlew.bat mode 100644 

1 answer

2


One option is to use git diff --summary, for according to the documentation, it shows only some condensed information such as creation, renaming and mode changes.

Then it would be:

git diff --summary HEAD

Or, if you want just for some files:

git diff --summary HEAD -- arquivo1 arquivo2 arquivo3

In a quick test I did, I changed the content (edited and added some lines) and the mode (git update-index --chmod= etc) two-file.

Using git diff HEAD, both changes are shown:

$ git diff HEAD
diff --git a/abc b/abc
old mode 100644
new mode 100755
index 8bea87f..9ae28cc
--- a/abc
+++ b/abc
@@ -1 +1,2 @@
-fasd
+fasdfad
+fd
diff --git a/gradlew b/gradlew
old mode 100755
new mode 100644
index 4793523..819f8dc
--- a/gradlew
+++ b/gradlew
@@ -1 +1,5 @@
-fad
+fadffdasfasdfads
+fasdfas

Using the option --summary, are shown only the mode changes along with the file name (below we have the files abc and gradlew):

$ git diff --summary HEAD
 mode change 100644 => 100755 abc
 mode change 100755 => 100644 gradlew

And finally, listing the changes of only one of the files:

$ git diff --summary HEAD -- abc
 mode change 100644 => 100755 abc
  • 1

    Just as an observation, I discovered that mentions HEAD do not work in repositories without history (obviously, right?). So my alternative was to complete the commit to verify that I had listed it with the correct permission and, if I had done wrong, I would git commit --amend

Browser other questions tagged

You are not signed in. Login or sign up in order to post.