This post will discuss about updating and committing only file permissions using Git version control.
How to Update and Commit Only a File’s Permissions Using Git?
To update and commit only file permissions using Git version control, check out the following steps:
- Move to the required repository.
- View the list of content.
- Display the file where HEAD is pointing with default permissions by running the βgit ls-tree HEADβ command.
- Execute the βgit update-index –chmod=+x <file-name>β command.
- Lastly, commit changes and verify them.
Step 1: Redirect to Desired Repository
At first, switch to the particular Git repository by running the βcdβ command:
Step 2: List Available Content
Next, execute the βlsβ command to display the all existing content of the current working repository:
According to the below-given output, repositories contain βfile1.txtβ and βfile2.pyβ files:
Step 3: Display HEAD Pointing SHA-Hash
Now, to show the SHA-hash of the commit where HEAD is pointing which contains the file by utilizing the βgit ls-treeβ command:
As you can see, the βfile1.txtβ contains the β644β permissions mode by default:
Step 4: Update Index
After that, execute the βgit update-indexβ command to update the permissions of the file where HEAD is pointing:
Here, the β–chmod=β will take the desired permissions mode. For instance, we specified the β+xβ which indicates the β755β permission mode:
Step 5: Commit Permission Updated Changes
Finally, commit the added changes to the Git repository by running the βgit commitβ command along with the particular commit message:
It can be observed that specifically file mode changes are committed:
Step 6: Verify File Change Permissions
Lastly, use the βgit ls-treeβ command along with the βHEADβ pointer:
As you can see, the permissions of the βfile1.txtβ are changed successfully from β644β to β755β mode:
Thatβs it! We have explained the easiest way to change and commit file permissions using Git.
Conclusion
To update and commit only file permissions using Git version control, first, move to the required repository and list its content. Then, execute the βgit ls-tree HEADβ command to display the file where HEAD is pointing with the default permissions. After that, use the βgit update-index –chmod=+x <file-name>β command. Lastly, commit changes and verify them. This post demonstrated the method of updating and committing only file permissions using Git version control.