Home > Enterprise >  What Does 100 Means in Git Diff Command ? I Know it Is Git File Mode, But Please Elaborate this File
What Does 100 Means in Git Diff Command ? I Know it Is Git File Mode, But Please Elaborate this File

Time:03-31

new file mode 100644 This 100 Here. I Know Last Three Numbers Meaning. But Not This File Mode Means. And Please Give Me All Information About. I Love To Be Fully Informed.

I Tried Searching About This File Mode But I Only Get Information About File Permission, Not This File Mode.

CodePudding user response:

According to the git documentation:

The code is a series of bits represented in octodecimal, from largest to smallest

  1. 4 bits for the file type
    • 1000 - regular file
    • 1010 - symbolic link
    • 1110 - git link
  2. 3 unused bits
  3. 9 bits for the permissions (644 or 755 only)

So your example of 100644 translates into binary as

001 000 000 110 100 100

file type: 1000 - Regular file
unused bits: 000
permissions: 110 100 100 - 644

It appears that trees also get a type code 0100 with no permissions, though I don't see that specified in the documentation.

CodePudding user response:

An entry in a Git tree object can have only five different "file modes". For example, my current Git source code contains these entries among many others:

040000 tree fe75d26ce528361a9ef3063415db408a7a1ca189    Documentation
120000 blob 81052262e0e43711f308ebc67a371def932cdccc    RelNotes
100755 blob 205541e0f7f81b1df4061215ae34a2742a45475d    generate-cmdlist.sh
100644 blob a25940d72e84e1ad6daba76a6c2845f320bc4df3    git.c
160000 commit 855827c583bc30645ba427885caa40c5b81764d2  sha1collisiondetection

The modes are

  • 100644 for a regular file
  • 100755 for an executable file
  • 040000 for a sub-tree (a directory)
  • 120000 for a symbolic link
  • 160000 for a submodule

The writers of Git could have chosen any text tokens to identify these five modes, but for historical reasons, they chose to write them as if they were the same values that would be found in a struct stat in C code, written as octal value. Proof of this arbitrary choice is that the value 160000 would never occur in a struct stat (it would be S_IFDIR|S_IFREG, an impossibility on a well-behaved system).

CodePudding user response:

It seems filemode refers to the executable bit (and not all permissions)

The use of core.fileMode is not advised. It just addresses the executable bit of mode, not the read/write bits.

As per the documentation of Git-Config

core.fileMode
Tells Git if the executable bit of files in the working tree is to be honored.

Some filesystems lose the executable bit when a file that is marked as executable is checked out, or checks out a non-executable file with executable bit on. git-clone[1] or git-init[1] probe the filesystem to see if it handles the executable bit correctly and this variable is automatically set as necessary.

A repository, however, may be on a filesystem that handles the filemode correctly, and this variable is set to true when created, but later may be made accessible from another environment that loses the filemode (e.g. exporting ext4 via CIFS mount, visiting a Cygwin created repository with Git for Windows or Eclipse). In such a case it may be necessary to set this variable to false. See git-update-index[1].

The default is true (when core.filemode is not specified in the config file).
  • Related