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

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

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

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Git

Gitはオープンソースの分散バージョン管理システム(DVCS)です。

GitHub

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

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

2009閲覧

githubでpushするとリジェクトされる

abbey_wakos

総合スコア17

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Git

Gitはオープンソースの分散バージョン管理システム(DVCS)です。

GitHub

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

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2018/06/23 03:04

最近、初めてGithubを使った者です。
pushしたらリジェクトされ、一週間何も前に進めなかったので質問さしてもらいます。
git pull origin masterをしてからpushしなおしても無理でした。
いくらやってもpushできません。

Changes not staged for commit:と表示されているので原因はこれだと思いました。更新されたファイルがaddされてないよと言われています。
ですが、ここからの対処法が初めてなので良く分かりません。

イメージ説明

もしよろしければ、アドバイス等いただきたいです。

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

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

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

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

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

guest

回答1

0

ベストアンサー

エラーメッセージに答えが書かれていますが、

(use "git add" and/or "git commit -a")

をすれば良いです。

$ git add controllers $ git commit $ git push

とかです。

gitは、ステージングと呼ばれる、コミット予約みたいな仕組みが有って、
コミットしたいファイルやフォルダをgit add で全て登録した上でcommitコマンドでコミットします。

投稿2018/06/23 04:18

編集2018/06/23 08:56
aquaS

総合スコア191

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

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

abbey_wakos

2018/06/23 05:59

解答ありがとうございます。 すみません説明不足でした。 controllersファイルをpushしたいのですが、それの解決策もそれでしょうか?
aquaS

2018/06/23 06:03

git add していなかっただけなので、 それさえすればgit pushはそのまま同じやり方で通るはずです。
abbey_wakos

2018/06/23 14:14

丁寧な対応ありがとうございます。 git add controllersだと fatal: pathspec 'controllers' did not match any filesと出ます ファイルがありませんと言うことだと思うのですが、、、
abbey_wakos

2018/06/23 15:13

すみません。もう一度実行したらaddできました。 しかし、コミットしてpushしたら また、リジェクトされました。 何とか頑張ってみます。 忙しい中大変申し訳ありません。 アドバイス等ありましたらお願いします
aquaS

2018/06/23 23:10

エラーメッセージを書いてみて下さい
abbey_wakos

2018/06/24 02:45

git addするとこのようになります。 ec2-user:~/environment/NBA_app/app (master) $ git add controllers ec2-user:~/environment/NBA_app/app (master) $ git status On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) (commit or discard the untracked or modified content in submodules) modified: controllers (modified content)
aquaS

2018/06/24 02:53

外しているかもしれませんが、、 左のツリーでは、Rails_lesson/NBA_app/app/controllers となっていますが、 environment/で大丈夫なのですか?
abbey_wakos

2018/06/24 02:55

ありがとうございます AWS cloud9を使用していますので大丈夫かと思います。
abbey_wakos

2018/06/24 03:16

何かヒントになるものが見つかったかもしれません。違ったら申し訳ありません。 ↓ ec2-user:~/environment/NBA_app/app (master) $ cd controllers ec2-user:~/environment/NBA_app/app/controllers (master) $ git status On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: players_controller.rb no changes added to commit (use "git add" and/or "git commit -a") ec2-user:~/environment/NBA_app/app/controllers (master) $ git add players_controller.rb ec2-user:~/environment/NBA_app/app/controllers (master) $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: players_controller.rb
aquaS

2018/06/24 03:36

git add が効いてないんですね。。不思議です。 git config --list としてみて頂けますか? その際、その出力内容から、メールアドレスとお名前は削除して頂いて大丈夫です。
aquaS

2018/06/24 03:39

あと、一応、 git --version もお願いします。
abbey_wakos

2018/06/24 03:40

かしこまりました。 ec2-user:~/environment/NBA_app/app/controllers (master) $ git config --list core.editor=/usr/bin/nano color.ui=true user.name=shingonakatani user.email=hoge@~~~~~~~~ core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true remote.origin.url=https://github.com/shingonakatani/mynba.git remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
abbey_wakos

2018/06/24 03:40

ec2-user:~/environment/NBA_app/app/controllers (master) $ git --version git version 2.13.6
aquaS

2018/06/24 03:49

ありがとうございます。それから、 alias -p | grep git もお願いします。
abbey_wakos

2018/06/24 03:57

いえいえ、ご教授してくれて大変感謝しています。。 ec2-user:~/environment/NBA_app/app/controllers (master) $ alias -p alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias python='python27' alias rvm-restart='rvm_reload_flag=1 source '\''/usr/local/rvm/scripts/rvm'\''' alias vi='vim' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
abbey_wakos

2018/06/24 04:02

ec2-user:~/environment/NBA_app/app (master) $ git grep fatal: no pattern given.
aquaS

2018/06/24 04:03

特に設定には問題が見つからないですね。。
aquaS

2018/06/24 04:05

これお願いします。 ls -la ~/environment/NBA_app/.git/index
abbey_wakos

2018/06/24 05:06

今の状況。。。 players_controller.rbをaddしてcommit → git add controllers → 先ほどaddが効いていなかったが、ステージングエリアに上げcommitまで成功できた。 git push origin master -> rejectされました。。 ec2-user:~/environment/NBA_app/app (master) $ git push origin master Username for 'https://github.com': hoge Password for 'https://hogehoge To https://github.com/shingonakatani/mynba.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/shingonakatani/mynba.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
abbey_wakos

2018/06/24 05:09

ec2-user:~/environment/NBA_app/app (master) $ ls -al ~/environment/NBA_app/.git/index -rw-rw-r-- 1 ec2-user ec2-user 173 Jun 24 04:51 /home/ec2-user/environment/NBA_app/.git/index
aquaS

2018/06/24 05:22

このrejectは、githubに、ローカルには無いコミットがpushされている、ということを表しています。 git pullでgithubのコミット内容をローカルに取り込めば、push出来るはずです。
abbey_wakos

2018/06/24 05:35

できませんでした このようになっています。 ec2-user:~/environment/NBA_app/app (master) $ git pull There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details. git pull <remote> <branch> If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/<branch> master ec2-user:~/environment/NBA_app/app (master) $ git push origin master Username for 'https://github.com': shingonakatani Password for 'https://shingonakatani@github.com': To https://github.com/shingonakatani/mynba.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/shingonakatani/mynba.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details
abbey_wakos

2018/06/24 05:36

ec2-user:~/environment/NBA_app/app (master) $ git pull origin master From https://github.com/shingonakatani/mynba * branch master -> FETCH_HEAD fatal: refusing to merge unrelated histories ec2-user:~/environment/NBA_app/app (master) $ git push origin master Username for 'https://github.com': shingonakatani Password for 'https://shingonakatani@github.com': To https://github.com/shingonakatani/mynba.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/shingonakatani/mynba.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
aquaS

2018/06/24 06:12 編集

このgithub側リポジトリは、元々別で作成したものを流用していたりします? ローカルのソース一式と無関係のコミットがgithubに上がっている為のエラーです。 github側の内容を破棄していいのであれば、一応方法は有ります。いかがです? ちなみに、新しいプロジェクトを始める際は、 1) githubにリポジトリを作成してローカルにクローン 2) クローンした環境でチェックアウトしてコミット作業 4) git pushでgithubに反映 の手順を行います。 もし、ローカルにリポジトリを先に作ってしまってgithubに反映したいという場合は、 1) githubにリポジトリを作成 2) git remote add origin githubのリポジトリパス 3) git push --set-upstream origin master とします。 上記どちらの方法でも、origin masterのパラメータが不要になり、以降の作業では、 git pull git push でいけます。
abbey_wakos

2018/06/24 10:39

問題解決できたようです チュートリアルように作ったディレクトリが原因でした。ご教授ありがとうございます。そして、すみません controllersのpushには成功したのですが、コードが見れませんでした。これも何か理由があると思うのですが初心者なもので全く分かりません。もし原因がありましたら教えていただきたいです。 https://github.com/shingonakatani
aquaS

2018/06/24 11:12

nbaのリポジトリですよね。push出来てないようです。 何もエラーが出てないのですよね??
abbey_wakos

2018/06/25 12:42

nbaのリポジトリでございます。pushした時にエラーは出てなかったと思います。 コントローラーでも、posts_controllerやteams_controllerがあるのでそれぞれ別々でコミットしないといけないわけではないんですよね、、 Submodule controllers updated from と書かれているのですが何かヒントになりますかね汗
aquaS

2018/06/26 14:20

元々、git addで登録出来たり出来なかったりとかも不思議なんですよね。。 申し訳ないですが、私は手詰まりですね。ごめんなさい。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問