Using git: committed changes in one branch affect 'master'
I have an issue with git which I feel may relate to permissions. The situation is as follows: I have two branches, 'master' and 'theming'. The file in question is called 'settings.php', and it has the permissions r--rw-rw-, and the owner listed is my own username. I am using Ubuntu 10.4LTS.
I produce the issue in the following manner:
- Checkout the theming branch
- Make change to settings.php
- Add and commit the change to 'theming'
- Checkout 'master' branch by using: $ git checkout master
After the preceding steps, I get the error 'unable to unlink settings.php', and I note that the file has also been changed in master. This als开发者_运维技巧o happens if I do it the other way around, ie. I change it in master, commit the change, and checkout theming. It then does not let me change back to the previous branch, as there are changes to be committed.
The only way I know of to avoid running into this issue is using $ sudo checkout [branchname]. This temporarily avoids the issue, but if I ever use checkout without sudo, I run into the same thing again and I have to worry about undoing all of the changes in my current branch.
Does anyone know how to solve this? I've looked around and I find issues relating to unlinking, but none like mine.
You shouldn't be checking it out as root in the first place. Try changing the repository permissions back to you:
# chown -R yourname ~/path/to/your/gitrepo
If you need to use a shared repository, check out the 'git init' manual for the --shared flag. Or there are lots of google hits for group settings that let you properly share a repo, but it is git version dependent so I won't recount it all here. The setting you're probably looking for, if so, is this one:
[core]
sharedrepository = 0660
(and then chgrp -R the directory and chmod g+s on the directory as well)
Why is the file in question read-only for owner? Git is not allowed to rewrite the contents or replace it when you switch branches.
This is Daniel M with a new name. First off, the file permissions were actually rw-rw-r--. Second, the comment by igorw was perfectly helpful. I did not have write permissions on the parent directory. As soon as I added this, my problem disappeared.
精彩评论