Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
git-tutorial
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael Alan Marsh
git-tutorial
Commits
7d2c9b2c
Commit
7d2c9b2c
authored
4 years ago
by
Michael Marsh
Browse files
Options
Downloads
Patches
Plain Diff
added update-index and ls-files
parent
692f02c2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.md
+42
-0
42 additions, 0 deletions
README.md
with
42 additions
and
0 deletions
README.md
+
42
−
0
View file @
7d2c9b2c
...
...
@@ -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
----
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment