Skip to content
Snippets Groups Projects
Commit 7d2c9b2c authored by Michael Marsh's avatar Michael Marsh
Browse files

added update-index and ls-files

parent 692f02c2
No related branches found
No related tags found
No related merge requests found
......@@ -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
----
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment