실행 파일에“git update-index --chmod = + x”자동 적용
나는 자주 bash 스크립트를 내 git 저장소에 추가하고 스크립트에는 .NET Framework 이전의 Linux 파일 시스템에서 실행 권한이 git add있습니다. 그러나 추가 된 파일을 원격 저장소로 푸시하고 다른 위치로 가져 오면 파일은 실행 불가능한 권한으로 표시됩니다. 문제를 해결하는 방법에는 두 가지가 있습니다.
1. chmod u+x $script
git commit -am "fixing the script permissions... again..."
또는
2. git update-index --chmod=+x $script
매번 권한을 수정하는 대신 git이 단순히 스크립트에 대한 파일 권한을 살펴보고 git add"이봐, 여기는 실행 파일입니다!"라고 인식하도록 하는 방법이 있습니까 ? 예상 할 수있는 권한으로 저장소에 직접 추가 하시겠습니까?
이를 수행하는 방법에는 여러 가지가 있습니다.
- Git 별칭
- Bash 별칭
- 또는 bash 및 git 별칭 결합
Git 별칭
항상 git 별칭 내에서 bash를 사용할 수 있습니다.
git 구성을 엽니 다.
vim ~/.gitconfig별칭 섹션을 추가합니다 (존재하지 않는 경우).
[alias] addscr = !sh -c 'if [[ ${0: -3} == ".sh" ]]; then git update-index --chmod=+x $0; git add $0'
Bash 별칭
bash 프로필 파일을 편집합니다.
vim ~/.bashrc파일 끝에 다음을 추가하십시오.
function gitadd(){ if [[ ${1: -3} == ".sh" ]] then git update-index --chmod=+x $1 fi git add $1 } alias gitadd='gitadd'
git 및 bash 별칭 결합
bash 프로필 파일을 편집합니다.
vim ~/.bashrc파일 끝에 다음을 추가하십시오.
function checkShellFile(){ return ${1: -3} == ".sh" } alias gitadd='checkShellFile ? git addsrcipt "$1" : && git add "$1"'git 구성 파일을 편집하십시오.
vim ~/.gitconfig별칭 섹션을 추가합니다 (존재하지 않는 경우).
[alias] addscript = !sh -c 'git update-index --chmod=+x $0 && git add $0'
위의 어느 것도 테스트되지 않았습니다.
자식 2.9.X는 / 2.10 (Q3 2016) 제공 chmod에 git add자체!
Edward Thomson ( )의 commit 4e55ed3 (2016 년 5 월 31 일)을 참조하십시오 . 도움 : Johannes Schindelin ( ) . (Merged by Junio C Hamano -- in commit c8b080a , 06 Jul 2016)ethomsondscho
gitster
add: 추가--chmod=+x/--chmod=-x옵션The executable bit will not be detected (and therefore will not be set) for paths in a repository with
core.filemodeset to false, though the users may still wish to add files as executable for compatibility with other users who do havecore.filemodefunctionality.
For example, Windows users adding shell scripts may wish to add them as executable for compatibility with users on non-Windows.Although this can be done with a plumbing command (
git update-index --add --chmod=+x foo), teaching thegit-addcommand allows users to set a file executable with a command that they're already familiar with.
You can see the origin of this new feature in "How to create file execute mode permissions in Git on Windows?" (Feb. 2011)
Here is a script to automatically apply “git update-index --chmod+x” to executable files:
for f in `find . -name '*.sh' -o -regex './s?bin/[^/]+' -o -regex './usr/sbin/[^/]+' -o -regex './usr/lib/[^/]+' `;do
( cd `dirname $f` && git update-index --chmod=+x `basename $f` )
done
A solution without fancy bash scripting:
- Set
fileMode = truein your.git/configfile (or by runninggit config core.filemode trueas others have pointed out) - Change the executable bit on the file's permissions and commit this change. (
chmod u+x $scriptas you pointed out). You only have to do this once. - Push to the remote
The next time you pull from there, git will set the committed executable bit on the file. I also had similar problems, this solved them.
fileMode = true tells git to track the only thing about permissions it can: the executable bit. This means that changes to the executable bit will be recognized by git as changes in the working tree and those changes will be stored in the repo with your next commit.
Once you committed the desired executable bit you can also reset your fileMode to false so next time git won't bother you with such changes when you don't want to commit them.
I don't think this can be done on the git add command, but you might be able to run a script just right after you run the git commit command, but before the commit is actually created.
Take a look at the pre-commit hook.
http://git-scm.com/book/en/Customizing-Git-Git-Hooks
Basically just create a file in your .git/hooks/ folder called pre-commit. (There should be samples already in your hooks folder, rename them to remove the ".sample" at the end to activate one.)
Theres a gotcha. Make sure your script runs git stash -q first so that your working on the actual staged versions of files.
I just added thru' Tortoise Git folder update. Right click on all files and update the execute permission checkbox to true and commit/push with message. Git Command line add/commit should also work.
ReferenceURL : https://stackoverflow.com/questions/14267441/automatically-apply-git-update-index-chmod-x-to-executable-files
'IT TIP' 카테고리의 다른 글
| C ++ 컴파일러는 언제부터 문자열 리터럴 문자 이스케이프에서 두 개 이상의 16 진수를 고려하기 시작 했습니까? (0) | 2021.01.08 |
|---|---|
| 열거 형 변수 기본값? (0) | 2021.01.08 |
| JavaScript는 왜 비교 연산자보다 크거나 작을까요? (0) | 2021.01.08 |
| 포인터로 붕괴되는 배열에 대한 예외? (0) | 2021.01.08 |
| 상자 속성은 무엇이며 어디에 추가합니까? (0) | 2021.01.08 |