简体   繁体   中英

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:

  1. Checkout the theming branch
  2. Make change to settings.php
  3. Add and commit the change to 'theming'
  4. 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 also 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM