git 提出コマンド#
提出手順#
- 現在のディレクトリのすべてのファイルをステージングエリアに追加する
git add .
- ワーキングディレクトリとステージングエリアの状態を表示する
git status
- ステージングエリアの内容をローカルリポジトリに追加する
git commit -m "commit info"
- リモートリポジトリ名とブランチ名を指定する
git push origin master
エラーが発生した場合
$ git push origin master
To gitee.com:tanggitee/embedded-learning-notes.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'gitee.com:tanggitee/embedded-learning-notes.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.
上記の 3 と 4 の間に以下のコマンドを追加すると、リモートリポジトリのコードを現在のブランチに強制的に更新できます。
git pull --rebase origin master
git を初めて Gitee(gitee)にプッシュする#
アカウントの作成#
Gitee アカウントを作成し、Gitee は国内で高速です。
Git をローカルにインストール#
Gitにアクセスして、オペレーティングシステムに応じた Git をローカルにダウンロードします。
SSH キー#
ローカルでキーを生成する#
デスクトップで右クリックして、git bash を開き、Git を使用する場合は最初に SSH を生成する必要があります。
ssh-keygen -t rsa -C "your_email"
生成されたキーは通常、操作システムのユーザーの.ssh ディレクトリにあります。
ローカルシステムに通知する#
キーをローカルシステムに通知します。
ssh-add ~/.ssh/id_rsa
(ここでCould not open a connection to your authentication agent.
と表示された場合は、まずssh-agent bash
を実行してください。)
生成された公開鍵を表示する#
cat ~/.ssh/id_rsa.pub
公開鍵をアップロードする#
この公開鍵を Gitee の SSH 公開鍵ページにコピーして貼り付けます。SSH 公開鍵を使用すると、コンピューターと Gitee 間の通信に安全な接続を使用できます(Git のリモートでは SSH アドレスを使用する必要があります)。
ユーザーの設定#
git bash
を開いて設定する必要があります。
git config --global user.name "your_Name"
git config --global user.email"your_email"
ローカル Git リポジトリの初期化#
git init
このコマンドを実行すると、.git
フォルダが追加されます。
変更ファイルの追加#
git add . // すべての変更ファイルを追加する
ファイルのコミット#
git commmit -am "message" // すべての変更ファイルをコミットする
リモートアドレスの追加#
git remote add origin [email protected]:your_gitee_username/repository_name.git
SSH テスト#
ssh -T [email protected]
を実行します。
Welcome to Gitee.com
と表示され、ユーザー名が表示される場合、SSH が正常に設定されています。
発生する可能性のあるエラー#
fatal: remote origin already exists.
と表示された場合は、git remote rm origin
を実行してください。
初回のプッシュ#
初回のプッシュ時には、次のエラーが発生する場合があります。
error: failed to push some refs to 'https://gitee.com/tomFat/interview.git'
そのため、プッシュする前にgit pull
を実行する必要があります。
2 つのバージョンリポジトリのマージ#
git pull origin master --allow-unrelated-histories
Github または Gitee にプッシュする#
git push -u origin master
またはgit push your_gitee_repository_name master # 指定したリポジトリのmasterブランチにプッシュする
またはgit push -u origin master -f # 強制プッシュ
【Gitee】ローカルでのコードのプッシュに成功しましたが、貢献度に反映されません。どのように処理しますか(解決済み 同様に github gitlab)#
これらの日々の gitee、github 関連の要件のために、いくつかの設定を変更し、ローカルコードを環境にプッシュしましたが、貢献(グリッドが点灯しない)が反映されませんでした。操作を調べて問題を解決しましたので、記録します。
実際には、設定情報が間違っているだけです。設定情報を変更してください。以下の方法でも問題が解決しない場合は、以下を続けて読んでください。
// 確認
git config --global -l
// 設定
git config --global user.name "your-username"
git config --global user.email "[email protected]"
12345
注意:Personal Settings には、Profile にメールアドレスがあり、その下に Emails にもメールアドレスがあります。Emails の下のものを使用してください。
Git の設定レベルには次の 3 つのタイプがあります:#
-
リポジトリレベル local【最も優先度が高い】
-
ユーザーレベル global【次に優先度が高い】
-
システムレベル system【最も優先度が低い】
git config --list すべての設定情報を表示するには、システムレベル、ユーザーレベル、リポジトリレベルの順に表示されます。
Git Config の一般的な設定オプション#
git config -e 設定ファイルを編集する
- git config --local -e リポジトリレベルの設定ファイルを編集する
- git config --global -e ユーザーレベルの設定ファイルを編集する
- git config --system -e システムレベルの設定ファイルを編集する
git config 設定項目を変更する
- git config --global user.email “[email protected]”
- git config --global user.name “Your Name”
-
git config 設定項目を追加する
- git config [--local|--global|--system] --add section.key value
git config 設定項目を取得する
- git config [--local|--global|--system] --get section.key
git config 設定項目を削除する
- git config [--local|--global|--system] --unset section.key