program tip

Git은 새 하위 모듈을 초기화 / 동기화 / 업데이트하지 않습니다.

radiobox 2020. 8. 25. 07:50
반응형

Git은 새 하위 모듈을 초기화 / 동기화 / 업데이트하지 않습니다.


다음은 내 .gitmodules파일 내용의 일부입니다 .

[submodule "src/static_management"]
        path = src/static_management
        url = git://github.com/eykd/django-static-management.git
[submodule "external/pyfacebook"]
        path = external/pyfacebook
        url = http://github.com/sciyoshi/pyfacebook.git

그러나 .git/config첫 번째 만 포함합니다.

[submodule "src/static_management"]
        url = git://github.com/eykd/django-static-management.git

두 번째 하위 모듈 ( external/pyfacebook)은 다른 개발자가 기능 분기에 추가했습니다. 나는 지금 개발을 계승했으며 기능 브랜치를 확인했습니다. 그러나 Git은 나를 위해 하위 모듈을 가져 오지 않습니다. 난 노력 했어:

  • git submodule init
  • git submodule update
  • git submodule update --init
  • git submodule sync
  • 모든 서브 모듈 정의를 제거 .git/config하고 실행 git submodule init. 이전에 존재하는 하위 모듈 만 복사하고 새 하위 모듈은 무시합니다.
  • .git/config수동으로 새 하위 모듈 정의를 입력 하고 git submodule update. 이전에 존재하는 하위 모듈 만 업데이트됩니다.

다양한 조합으로 가능하지만 git은의 .git/config새로운 내용을 기반으로 업데이트되지 .gitmodules않으며 external/pyfacebook폴더를 생성 하고 하위 모듈의 내용을 가져 오지 않습니다 .

내가 무엇을 놓치고 있습니까? 수동 개입 (에 수동으로 하위 모듈 항목 추가 .git/config)이 정말로 필요하며 그 이유는 무엇입니까?

편집 : 수동 개입이 작동하지 않습니다. 새 하위 모듈 항목을 수동으로 추가 .git/config해도 아무 일도 일어나지 않습니다. 새 하위 모듈은 무시됩니다.


최근에 git 버전 1.7.0.4로 업그레이드하셨습니까? 나는 지금 비슷한 문제를 겪고 있습니다 ...

편집 : 내 문제를 해결했지만 문제가 어디에 있는지 전혀 모릅니다. .git / config 및 .gitmodules에서 수동으로 하위 모듈 항목을 제거하고 사용 단계 (git submodule add 등 ...)로 하위 모듈을 다시 추가했습니다. Worksforme이지만이 스레드에 값을 추가하지 않습니다.


.gitmodules 파일이 커밋되었지만 실제 서브 모듈 커밋 (즉, 서브 모듈의 커밋 ID 기록)은 그렇지 않은 것으로 밝혀졌습니다.

수동으로 추가하면 트릭을 수행하는 것처럼 보였습니다. 예 :

git submodule add http://github.com/sciyoshi/pyfacebook.git external/pyfacebook

(.git / config 또는 .gitmodules에서 아무것도 제거하지 않아도)

그런 다음 ID를 올바르게 기록하도록 커밋하십시오.

이 작업 답변에 몇 가지 추가 설명 추가 : git submodule init 또는 git submodule update가 작동하지 않으면 위에서 설명한대로 git submodule add url이 트릭을 수행해야합니다. 하나는 이것을 교차 확인할 수 있습니다.

 git config --list

그리고 git config --list 명령의 결과에서 가져 오려는 하위 모듈의 항목을 가져와야합니다. 구성 결과에 하위 모듈 항목이있는 경우 이제 일반적인 git 하위 모듈 업데이트 --init가 하위 모듈을 가져와야합니다. 이 단계를 테스트하려면 수동으로 하위 모듈의 이름을 바꾼 다음 하위 모듈을 업데이트 할 수 있습니다.

 mv yourmodulename yourmodulename-temp
 git submodule update --init

하위 모듈에 로컬 변경 사항이 있는지 확인하려면 git status -u (서브 모듈의 변경 사항을보고 싶은 경우) 또는 git status --ignore-submodules (변경 사항을보고 싶지 않은 경우)를 통해 확인할 수 있습니다. 서브 모듈).


git 버전 2.7.4. 이 명령은 로컬 코드를 업데이트합니다. git submodule update --init --force --remote


git이 무시 init하고 update명령 할 때 동일한 문제 가 있었고 아무것도하지 않았습니다.

어떻게 고치는 지

  1. 하위 모듈 폴더는 git repo에 커밋되어야합니다.
  2. .gitignore에 없어야합니다.

해당 요구 사항이 충족되면 작동합니다. 그렇지 않으면 모든 명령이 메시지와 결과없이 실행됩니다.

모든 작업을 수행했지만 여전히 작동하지 않는 경우 :

  1. 수동으로 서브 모듈 추가, 예 : git submodule add git@... path/to
  2. git submodule init
  3. git submodule update
  4. 모든 파일을 커밋하고 푸시- .gitmodules모듈 폴더 (폴더의 내용은 커밋되지 않음)
  5. 로컬 git repo를 삭제하십시오.
  6. 새 복제
  7. .git/config아직 하위 모듈이 없는지 확인하십시오.
  8. 이제 git submodule init- 그러면 모듈이 등록되었다는 메시지가 표시됩니다.
  9. git submodule update -모듈을 가져옵니다
  10. 이제 살펴보면 .git/config등록 된 하위 모듈을 찾을 수 있습니다.

정렬 마법의, 그러나 오늘 나는 달렸다 git submodule init다음에 git submodule sync다음에 git submodule update그것은 ... 매직을 내 서브 모듈을 당겨 시작? 혹시! 이것은 정말로 Git에서 가장 성가신 경험 중 하나입니다.

Scratch that. I actually got it working by doing git submodule update --init --recursive. Hope this helps.

PS: Make sure you are in the root git directory, not the submodule's.


There seems to be a lot of confusion here (also) in the answers.

git submodule init is not intended to magically generate stuff in .git/config (from .gitmodules). It is intended to set up something in an entirely empty subdirectory after cloning the parent project, or pulling a commit that adds a previously non-existing submodule.

In other words, you follow a git clone of a project that has submodules (which you will know by the fact that the clone checked out a .gitmodules file) by a git submodule update --init --recursive.

You do not follow git submodule add ... with a git submodule init (or git submodule update --init), that isn't supposed to work. In fact, the add will already update the appropriate .git/config if things work.

EDIT

If a previously non-existing git submodule was added by someone else, and you do a git pull of that commit, then the directory of that submodule will be entirely empty (when you execute git submodule status the new submodule's hash should be visible but will have a - in front of it.) In this case you need to follow your git pull also with a git submodule update --init (plus --recursive when it's a submodule inside a submodule) in order to get the new, previously non-existing, submodule checked out; just like after an initial clone of a project with submodules (where obviously you didn't have those submodules before either).


I had the same problem.

.gitmodules had the submodule, but after a git submodule init command it wasn't in .git/config.

Turns out the developer who added the submodule also added the submodule directory to the .gitignore file. That doesn't work.


According to the answer from Dave James Miller I can confirm that it worked for me. The important thing here was to commit the subprojects commit ID. Just to have the entry in .gitmodules was not enough.

Here is an appropriate commit:

https://github.com/dirkaholic/vagrant-php-dev-box/commit/d5f4c40bdbd80eefbb5ac6029823733f591435ae


Same as you I found that git submodule sync does not do what you expect it to do. Only after doing an explicit git submodule add again does a submodule url change.

So, I put this script in ~/bin/git-submodule-sync.rb:

https://gist.github.com/frimik/5125436

And I also use the same logic on a few post-receive git deploy scripts.

All I need to do now is edit .gitmodules, then run this script and it finally works like I thought git submodule sync was supposed to.


I had the same problem today and figured out that because I typed git submodule init then I had those line in my .git/config:

[submodule]
   active = .

I removed that and typed:

git submodule update --init --remote

And everything was back to normal, my submodule updated in its subdirectory as usual.


I had the same problem but none of the solutions above helped. The entries in the .gitmodules and in .git/config were right but the command git submodules update --init --recursive was doing nothing. I also removed the submodule directory and did run git submodules update --init --recursive and got the submodule directory back but with exactly the same commit as before.

I found the answer on this page. The command is:git submodule update --remote


When I saw this today, a developer had moved part of the tree into a new sub-directory and it looks as though his git client did not record the updated Subproject rules in the tree, instead they were just nuked, leaving .gitmodules referring both to stale locations and to subprojects which no longer existed in the current tree.

Adding the submodules back in, and comparing the commit shas of the submodule to those found in git show $breaking_commit_sha (search for lines matching regexp ^-Subproject) to adjust as needed fixed things.


I had a similar problem with a submodule. It just didn't want to be cloned/pulled/updated/whatever.

When trying to re-add the submodule using git submodule add git@my-repo.git destination I got the following output:

A git directory for 'destination' is found locally with remote(s):
  origin        git@my-repo.git
If you want to reuse this local git directory instead of cloning again from
  git@my-repo.git
use the '--force' option. If the local git directory is not the correct repo
or you are unsure what this means choose another name with the '--name' option.

So, I tried to enforce the add command:
git submodule add --force git@my-repo.git destination

That worked in my case.


  • Remove the submodule from your .git/config
  • Run git submodule init command
  • Go to your submodule directory and run git pull origin master

It should works now


Deleting submodule dir and its contents ("external/pyfacebook" folder) if it exists before git submodule add ... might fix problems.


For the record:
I created the same issue by adding an empty repository as submodule. In this case, there was no reference hash available for the submodule, leading to the error described by the original poster.

Force-adding the repository after having committed to it solved the issue (as in Arvids post)
git submodule add --force git@my-repo.git destination


Thinking that manually setting up .gitmodules is enough is WRONG

My local git version 2.22.0 as of this writing.

So I came to this thread wondering why wasn't git submodule init working; I setup the .gitmodules file and proceeded to do git submodule init ...

IMPORTANT

  1. git submodule add company/project.git includes/project is required (when adding the module for the first time), this will:

    • add config to .git/config
    • update the .gitmodules file
    • track the submodule location (includes/project in this example).
  2. you must then git commit after you have added the submodule, this will commit .gitmodules and the tracked submodule location.

When the project is cloned again, it will have the .gitmodules and the empty submodules directory (e.g. includes/project in this example). At this point .git/config does not have submodule config yet, until git submodule init is run, and remember this only works because .gitmodules AND includes/project are tracked in the main git repo.

Also for reference see:

참고URL : https://stackoverflow.com/questions/3336995/git-will-not-init-sync-update-new-submodules

반응형