aboutsummaryrefslogtreecommitdiff
path: root/doc/walkthrough/modifying_annexed_files.mdwn
blob: 1f7a7efb7770f3b87895951cdf5328ab93ce92ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Normally, the content of files in the annex is prevented from being modified.
That's a good thing, because it might be the only copy, you wouldn't
want to lose it in a fumblefingered mistake.

	# echo oops > my_cool_big_file
	bash: my_cool_big_file: Permission denied

In order to modify a file, it should first be unlocked.

	# git annex unlock my_cool_big_file
	unlock my_cool_big_file (copying...) ok

That replaces the symlink that normally points at its content with a copy
of the content. You can then modify the file like any regular file. Because
it is a regular file.

(If you decide you don't need to modify the file after all, or want to discard
modifications, just use `git annex lock`.)

When you `git commit`, git-annex's pre-commit hook will automatically
notice that you are committing an unlocked file, and add its new content
to the annex. The file will be replaced with a symlink to the new content,
and this symlink is what gets committed to git in the end.

	# echo "now smaller, but even cooler" > my_cool_big_file
	# git commit my_cool_big_file -m "changed an annexed file"
	add my_cool_big_file ok
	[master 64cda67] changed an annexed file
	 1 files changed, 1 insertions(+), 1 deletions(-)

There is one problem with using `git commit` like this: Git wants to first
stage the entire contents of the file in its index. That can be slow for
big files (sorta why git-annex exists in the first place). So, the
automatic handling on commit is a nice safety feature, since it prevents
the file content being accidentally committed into git. But when working with
big files, it's faster to explicitly add them to the annex yourself
before committing.

	# echo "now smaller, but even cooler yet" > my_cool_big_file
	# git annex add my_cool_big_file
	add my_cool_big_file ok
	# git commit my_cool_big_file -m "changed an annexed file"