From 7d2c9b2ca97a0600acd1a79e9bd6e731168e0515 Mon Sep 17 00:00:00 2001 From: Michael Marsh <mmarsh@cs.umd.edu> Date: Mon, 9 Nov 2020 15:25:26 -0500 Subject: [PATCH] added update-index and ls-files --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/README.md b/README.md index c77640f..1348d54 100644 --- a/README.md +++ b/README.md @@ -603,6 +603,48 @@ checkout were just on. This is probably the most likely way you'll create a branch, when you use them. +update-index and ls-files +-------------------------- + + These are two very useful commands when you're writing scripts + and storing them in git. I have often seen students commit a + script to git, and then ask why it's not running when I am doing + a grading pass. The reason is that they haven't told git that the + script file should be executable. If you set the execute bit + before adding the file to a commit for the first time, git will + pick this up automatically. If, however, you add and commit it + before making it executable, you have to go back and tell git to + record the executable bit for the file. + + Fortunately, this is easy to do using `git update-index`. This + command tells git that you want to change some of the metadata + about one or more files, as opposed to modifying the contents of + the file. Let's say we have `foo.sh`, but git doesn't (yet) know + that it should be an executable bash script. We can fix this by + running + + git update-index --chmod=+x foo.sh + + This behaves like the standard Posix `chmod` (change mode) command, + which is used to change permissions on a file or directory. In + particular, we're telling it to add the executable (x) bit. This + also adds the file to a commit, so you'll then just need to do + the actual commit (and push, if necessary. + + Let's say you're not sure if the executable bit is set. That's where + `git ls-files` comes in. If you run + + git ls-files --stage foo.sh + + it will show you the index entry for the file. The first column + will be an octal number like `100644` or `100755`. The last three + digits tell you (respectively) the owner, group, and other + permissions. The first bit is whether the file is readable, the + second writable, and the third exectuable. That means `100644` + means the owner can read and write the file, and everyone else + can only read it. `100755` means the executable bit is set for + everyone. + tag ---- -- GitLab