質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

Q&A

解決済

1回答

20114閲覧

Githubでディレクトリの中身がアップロードされない

yuki0000

総合スコア12

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

1グッド

5クリップ

投稿2018/05/26 11:46

編集2018/05/26 14:17

Githubのリモートリポジトリusername/hogeに、ローカルのhome/directory1(directory1は複数のファイルやディレクトリを含むディレクトリ)をアップロードしたいと思っています。

そのために、

cd home git init git add directory1 git commit -m "first commit" git push origin master

として、一応Githubのリモートリポジトリusername/hogeにはdirectory1が表示されました。

しかし、ローカルのdirectory1の中には複数のファイルやディレクトリが入っているのですが、リモートではdirectory1の中を確認することができません。

どうすればdirectory1の中身を含めてgit pushできるでしょうか。

なお、.gitignoreはこのディレクトリには存在しません。


<追記1>

$ git ls-files
directory1
$ git status ignored
ブランチ master
nothing to commit, working directory clean

となります。

$ cd directory1
とすると
$ git ls-files
file1 file2 file3 directory1 directory2 directory3 ...

とdirectory1内のファイル、ディレクトリが表示されます。

$ cd directory1
$ git add .
$ cd ..
$ git commit
とすると、

ブランチ master
Changes not staged for commit:
modified: directory1 (modified content)

no changes added to commit

という結果が出ます。


<追記2>

$ rm -rf directory1/.git

としても、

$ git ls-files directory1 $ git add . $ git commit ブランチ master nothing to commit, working directory clean

と先ほどと結果は変わりませんでした。
ちなみに、homeの中にdirectory1, .gitがある状態で、

$ cd home $ git add directory1

などとしています。

DrqYuto👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

git pushはローカルリポジトリ内のコミットをリモートリポジトリに転送するものです。
なのでgithubにファイルが転送されていないのであれば、ローカルリポジトリにコミットされていないということです。
ローカルリポジトリの内容を確認してみてください。

sh

1# リポジトリで管理しているファイルを一覧表示する 2$ git ls-files 3 4# gitの管理対象外になっているファイルを一覧表示する 5$ git status ignored

追記

directory1がリポジトリになっているため、directory1の親ディレクトリのリポジトリからは管理対象とされないようです。
directory1がリポジトリになっているのが間違いなら、directory1内の.gitディレクトリを削除してください。

sh

1$ rm -rf direcotry1/.git 2$ git add . 3$ git commit

追記2

以下のように確認作業を行ってみました。

sh

1$ mkdir -p zzz/directory1 2 3# directory1にgitリポジトリ作成してファイルを登録 4$ cd zzz/directory1 5$ git init 6$ touch hoge fuga 7$ git add . 8$ git commit -m INIT 9 10# zzzにgitリポジトリ作成してdirectory1を登録 11$ cd .. 12$ git init 13$ git add . 14warning: adding embedded git repository: direcotory1 15ヒント: You've added another git repository inside your current repository. 16ヒント: Clones of the outer repository will not contain the contents of 17ヒント: the embedded repository and will not know how to obtain it. 18ヒント: If you meant to add a submodule, use: 19ヒント: 20ヒント: git submodule add <url> direcotory1 21ヒント: 22ヒント: If you added this path by mistake, you can remove it from the 23ヒント: index with: 24ヒント: 25ヒント: git rm --cached direcotory1 26ヒント: 27ヒント: See "git help submodule" for more information. 28 29$ git commit -m INIT 30 31# directory1のgitリポジトリを削除して状態確認 32$ rm -rf direcotory1/.git 33$ git status 34ブランチ master 35nothing to commit, working tree clean 36 37# directory1内のファイルを登録してみる 38$ git add direcotory1/* 39fatal: Pathspec 'direcotory1/fuga' is in submodule 'direcotory1'

directory1がサブモジュールとして登録されていると、directory1のgitリポジトリを削除してもdirectory1以下のファイルをリポジトリに追加できないようです。

以下のようにdirectory1を一旦削除することで、directory1以下のファイルを追加することができました。

sh

1$ git rm --cached direcotory1 2$ git add . 3$ git status 4ブランチ master 5コミット予定の変更点: 6 (use "git reset HEAD <file>..." to unstage) 7 8 deleted: direcotory1 9 new file: direcotory1/fuga 10 new file: direcotory1/hoge

投稿2018/05/26 12:20

編集2018/05/26 15:06
tkmtmkt

総合スコア1800

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yuki0000

2018/05/26 13:22

ご回答ありがとうございます。 $ git ls-files directory1 $ git status ignored ブランチ master nothing to commit, working directory clean となります。 $ cd directory1 とすると $ git ls-files file1 file2 file3 directory1 directory2 directory3 ... とたくさん出ます。 この場合、どうすればdirectory1内のファイル、ディレクトリをローカルリポジトリにコミットできるのでしょうか。 $ cd directory1 $ git add . $ cd .. $ git commit とすると、 ブランチ master Changes not staged for commit: modified: directory1 (modified content) no changes added to commit という結果が出ます。
tkmtmkt

2018/05/26 13:54

確認結果などは他の人が閲覧して有用な情報となることを意識して、コメント欄ではなく質問欄に追記していったほうがよいです。
yuki0000

2018/05/26 14:18

なるほどです。質問欄に追記しました。 まだdirectory1内は管理対象になっていないようです。
yuki0000

2018/05/27 10:04

無事にできました。ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問