[組み込み開発 Linux 共通コマンドシリーズ 4.1 -- git Push リモートブランチとローカルブランチビュー]


概要

日常業務で、コードをローカルにコピーした後git clone、または repo init && repo sync を使用した後、コードを変更するためにどのコマンドを使用すればよいかわかりません。 /span> の特定のパラメータを見つける方法を段階的に紹介します。 の正しいコマンド。 git push をサーバーに接続します。この記事では、私の仕事で遭遇した実際の問題を例として、 git pushgit push

git プッシュ構文

ご存知のように、push コマンドは、現在のローカル ブランチのコードを指定されたリモート ブランチにプッシュするために使用されます。コマンドの形式は次のとおりです。

git push <远程主机名> <本地分支名>:<远程分支名>

使用git push コマンドで<ローカルブランチ名>のコードをにプッシュします。 <リモート ホスト名><リモート ブランチ名>

  • <リモート ホスト名>: プッシュ先のリモート ホストを指します。プロジェクトのクローンを作成するとき、git が自動的にサポートします。ホストの名前は です。 a>origin通常、 はこの名前を変更しません
  • <ローカル ブランチ名>: ローカル ブランチの名前です。コマンド git branch を使用すると、どのブランチがあるかを表示できます。地元で。
  • <リモート ブランチ名>: リモート ホストのブランチ名を指します。リモート ホストにこのブランチがない場合は、新しいブランチが作成されます。

ステップ 1: git リモート ホスト名を表示する

使用 git remote 命令或者 git remote -v 命令

[10:45:53]sam@linux (*^~^*) ~/sam/workbase/npu_code/device$ git remote
arm-val

または

[10:47:31]sam@linux (*^~^*) ~/sam/workbase/npu_code/device$ git remote -v
arm-val ssh://codereview.armtech.com/arm_val/device (fetch)
arm-val ssh://codereview.armtech.com/arm_val/device (push)

リモート ホスト名は arm-val であることがわかります。

ステップ 2: git リモート ブランチ名を表示する

git branch -vv を使用すると、リモート ブランチの名前が arm-val/arm_main であることがわかります。

[10:54:31]sam@linux (*^~^*) ~/sam/workbase/npu_code/device$ git branch -vv
* test b3f0b95 [arm-val/arm_main: ahead 1] device: compile: support npu device compile

ステップ 3: git ローカル ブランチ名を表示する

HEAD は、作業中の ローカル ブランチ を指す特別なポインタを表し、 とみなすことができます。 as は、 ローカル ブランチのエイリアスです。 git はこれを使用して、現在のワークスペースがどのブランチにあるかを知ることができます。

refs/for は、コードをサーバーに送信した後、マージ操作を実行する前にコード レビューを行う必要があることを意味しますが、 refs/heads は必要ありません。

git push のコマンドは次のとおりです。

git push  <远程主机名> HEAD:refs/for/<远程分支名>

サンプルデモンストレーション

リモート ブランチ名の表示:

[10:45:26]sam@linux (*^~^*) ~/sam/workbase/npu_code/device$ git branch -vv
* test b3f0b95 [arm-val/arm_main: ahead 1] device: compile: support npu device compile

リモート ホスト名の表示:

[10:37:30]sam@linux (*^~^*) ~/sam/workbase/npu_code/device$ git remote -v
arm-val ssh://codereview.armtech.com/arm_val/device (fetch)
arm-val ssh://codereview.armtech.com/arm_val/device (push)

コードのプッシュを開始します:
git push arm-val HEAD:refs/for/arm_main を使用してコードのプッシュを開始します:

[10:37:00]sam@linux (*^~^*) ~/sam/workbase/npu_code/device$ git push arm-val HEAD:refs/for/arm_main
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 16 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 485 bytes | 485.00 KiB/s, done.
Total 4 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (3/3)
remote: Processing changes: refs: 1, done
remote: ERROR: commit 4b80700: missing Change-Id in message footer
remote:
remote: Hint: to automatically insert a Change-Id, install the hook:
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 29418 sam@codereview.armtech.com:hooks/commit-msg ${
    
    gitdir}/hooks/
remote: or, for http(s):
remote:   f="$(git rev-parse --git-dir)/hooks/commit-msg"; curl -o "$f" https://codereview.armtech.com/tools/hooks/commit-msg ; chmod +x "$f"
remote: and then amend the commit:
remote:   git commit --amend --no-edit
remote: Finally, push your changes again
remote:
To ssh://codereview.armtech.com/arm_val/device
 ! [remote rejected] HEAD -> refs/for/arm_main (commit 4b80700: missing Change-Id in message footer)
error: failed to push some refs to 'ssh://codereview.armtech.com/arm_val/device'

プロンプトに従います。

[10:37:46]sam@linux (*^~^*) ~/sam/workbase/npu_code/device$  gitdir=$(git rev-parse --git-dir); scp -p -P 29418 sam@codereview.armtech.com:hooks/commit-msg ${
    
    gitdir}/hooks/
[10:38:01]sam@linux (*^~^*) ~/sam/workbase/npu_code/device$ git commit --amend --no-edit
[uefi_test b3f0b95] device: compile: support npu device compile
 Date: Wed Dec 6 14:38:57 2023 +0800
 1 file changed, 3 insertions(+), 3 deletions(-)

修正後に再投稿:

[10:38:15]sam@linux (*^~^*) ~/sam/workbase/npu_code/device$ git push arm-val HEAD:refs/for/arm_main
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 16 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 520 bytes | 520.00 KiB/s, done.
Total 4 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (3/3)
remote: Processing changes: refs: 1, new: 1, done
remote: commit b3f0b95: Missing issue-id in commit message
remote: Commit b3f0b957b0c5dd4911707855dec98f321dcfa737 not associated to any issue
remote:
remote: Hint: insert one or more issue-id anywhere in the commit message.
remote:       Issue-ids are strings matching (DPTS[WE][A-Z]*-[0-9]+)
remote:       and are pointing to existing tickets on its-jira Issue-Tracker
remote:
remote: SUCCESS
remote:
remote:   https://codereview.armtech.com/c/arm_val/device/+/9820 device: compile: support npu device compile [NEW]
remote:
To ssh://codereview.armtech.com/arm_val/device
 * [new reference]   HEAD -> refs/for/arm_main

この時点で、git Push コマンドは正常に完了しました。
ヒント: 問題が発生した場合は、さらに確認する必要があります。子供の頃に学んだスローガン: "わからない場合は聞いてください」…検索と分析が終わったら見直すのがベストです。誰かが答えを教えてくれても、なぜそうなのかはわかりません。 ! ! わからない場合は調べてください」を「

おすすめ

転載: blog.csdn.net/sinat_32960911/article/details/134872513
おすすめ