14

Rails 3 プロジェクトにいくつかの Haml テンプレートを追加しました。

git clone git://github.com/psynix/rails3_haml_scaffold_generator.git lib/generators/haml

これらのファイルのいくつかを編集しようとしたときに、これがサブモジュールであることがわかったため、lib/generators/hamlディレクトリ内で行った変更をコミットできませんでした。git status今私が得るたびに

# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   lib/generators/haml
#
no changes added to commit (use "git add" and/or "git commit -a")

しかしgit add lib/generators/haml、効果はありません。私は本当にサブモジュールではなくファイルを持ちたいだけですが、サブモジュールを取り除くことは不可能だと思っています:

> git rm --cached lib/generators/haml
rm 'lib/generators/haml'
> git status

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    lib/generators/haml
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   lib/generators/

> git commit -m "Removed submodule"

[master 02ae4c7] Removed submodule
 1 files changed, 0 insertions(+), 1 deletions(-)
 delete mode 160000 lib/generators/haml

> git status

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   lib/generators/
nothing added to commit but untracked files present (use "git add" to track)

> git add lib/generators/haml
> git status

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   lib/generators/haml
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   lib/generators/haml

> git commit -m "Re-added lib/generators/haml"

[master c966912] Re-added lib/generators/haml
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 160000 lib/generators/haml

> git status

# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   lib/generators/haml

追加git addの s は役に立ちません。私がしようとするとgit rm -rf lib/generators/haml、私は得る

fatal: git rm: 'lib/generators/haml': Operation not permitted

それはただ死ぬことはありません!submodules を削除する方法を調べましたが、この場合、.submodulesファイルはなく、サブモジュールについての言及もありません.git/config。しかし、実行するgit submodule updateと、

No submodule mapping found in .gitmodules for path 'lib/generators/haml'

ディレクトリを削除しましたが、同じ結果が得られます! どうしたの?.gitmodulesサブモジュールを削除するためだけにファイルを作成する必要がありますか?

4

3 に答える 3

6

追跡されていないファイルがある場合、サブモジュールは git status で変更済みとして表示されます。を呼び出すgit diff lib/generators/hamlと、ほとんどの場合、次のように表示されます。

diff --git a/lib/generators/haml b/lib/generators/haml
index 3019fec..653c59a 160000
--- a/lib/generators/haml
+++ b/lib/generators/haml
@@ -1 +1 @@
-Subproject commit 653c59ad72925c9ccbde67e8e484e15d4b6dd25d
+Subproject commit 653c59ad72925c9ccbde67e8e484e15d4b6dd25d-dirty

これは、このサブモジュール内に追跡されていないファイルが残っていることを意味します。親プロジェクトのコマンドを使用して追加することはできません。代わりに、sumbodule をトラバースしてそれらを追加する (または にエントリを追加する.gitignore) 必要があります... または、ステータス メッセージを無視することもできます。

最新の git バージョン (1.7.1 だと思います) では、この情報がステータスに表示されます。

# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   lib/generators/haml (untracked content)
于 2010-07-24T21:14:14.473 に答える
6

サブモジュールがない場合、それ (つまり ' haml') が実際にはサブモジュールではない可能性はありますか?

git clone git://github.com/psynix/rails3_haml_scaffold_generator.git lib/generators/haml

意味:lib/generators/hamlディレクトリを作成し、そこに の master ブランチをチェックアウトしgit://github.com/psynix/rails3_haml_scaffold_generator.gitます。

git status新しいレポのルート ( lib/generators/haml) からではなく、3 レベル上 (場所) から実行できるということlibは、レポ内にレポを複製したことを意味します。

両方のレポは独立して動作しますが、親レポの に追加 lib/generators/hamlする必要があります (hits SO questionのように)。.gitignore

于 2010-07-24T21:20:13.363 に答える
0

あなたが使用できた可能性があります:

git add lib/generators/haml/

サブモジュール内のファイルを HEAD に追加し、サブモジュールを削除します。ただし、実際にはサブモジュールがないため、機能しない可能性があります。

パスの後にスラッシュがあることに注意してください。この git を配置すると、サブモジュールが削除され、HEAD に配置されます。

git add lib/generators/haml

これは、コミットが git サブモジュールのサブモジュールからチェックアウトされるように変更するだけです。

于 2011-04-11T14:59:04.227 に答える