Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locking files in git repository #202

Merged
merged 3 commits into from
Jul 11, 2014
Merged

Conversation

julionc
Copy link
Contributor

@julionc julionc commented Dec 5, 2013

The way to ignore certain files that are already committed is:

git update-index --skip-worktree filename

I thought that this shortcut might be useful to exclude/protect files from version control.

Usage:

git proctect-file config/database.yml

@tj
Copy link
Owner

tj commented Dec 5, 2013

hmm wonder if "freeze" or "lock" would maybe be better

@julionc
Copy link
Contributor Author

julionc commented Dec 6, 2013

yes, you are right.
Which of these do you think git-lock-file or git-lock ?

@tj
Copy link
Owner

tj commented Dec 6, 2013

lock sounds good to me

@LoicMahieu
Copy link

Faboulus! I wasn't aware about git update-index --skip-worktree ! It's awesome!
Would be great to have a git unlock ?

@pzelnip
Copy link

pzelnip commented Dec 13, 2013

This is hugely useful. One suggestion (to echo the above): I'd like to see an unlock to go along with the lock.

One question: the update-index docs (https://www.kernel.org/pub/software/scm/git/docs/git-update-index.html) discuss --assume-unchanged as an alternative to --skip-worktree. Is there a reason why --skip-worktree should be preferred?

@pzelnip
Copy link

pzelnip commented Dec 13, 2013

To answer my own question, this StackOverflow answer explains the difference.

@pzelnip
Copy link

pzelnip commented Dec 13, 2013

One other comment, perhaps "lock" is not the right verb. You're not really "locking" the file (which would imply the file cannot change, but this is not true -- the file most definitely can change), but rather telling Git to stop tracking changes. Perhaps git ignore-future-changes <filename> would be more appropriate (though rather verbose)?

@julionc
Copy link
Contributor Author

julionc commented Dec 28, 2013

Thanks @pzelnip
I don't know if @visionmedia likes this PR, but you can use git alias for a while.
Furthermore, I think is a better way.

   git config --global alias.lock "update-index --skip-worktree"
   git config --global alias.lock "update-index --no-skip-worktree"

@hemanth
Copy link
Collaborator

hemanth commented Jul 9, 2014

@julionc Willing to proceed?

@julionc
Copy link
Contributor Author

julionc commented Jul 11, 2014

Updated cc/ @hemanth

@hemanth
Copy link
Collaborator

hemanth commented Jul 11, 2014

@julionc Awesome stuff!

hemanth added a commit that referenced this pull request Jul 11, 2014
Locking files in git repository.
@hemanth hemanth merged commit 390ba55 into tj:master Jul 11, 2014
@Bodacious
Copy link

I love git extras so far—hugely useful!

Can someone please explain to me the benefit of locking files in git?

@qw3rtman
Copy link
Collaborator

From what I understand, if you git lock <file>, it will hide <file> in git status.

This makes it useful for config files that may be changed often (or left completely untracked, leading to a bunch of files being shown as untracked in git status), with no contribution to the actual code.

See this StackOverflow answer for more info.

@Bodacious
Copy link

So this is a feature I'd use for a file already committed to the repo, rather than one I want to ignore (like config/database.yml?

tardypad pushed a commit to tardypad/git-extras that referenced this pull request Jul 13, 2016
Locking files in git repository.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants