商城网站建设开发多少钱,文档做网站,网站开发公司经营范围,ssh jsp做网站文章目录 概述git push 语法步骤1#xff1a;git 远程主机名查看步骤2#xff1a;git 远程分支名查看步骤3#xff1a;git 本地分支名查看示例演示 概述
在日常工作中#xff0c;将代码 git clone 本地之后#xff0c;或者使用repo init repo sync 之后不知道… 文章目录 概述git push 语法步骤1git 远程主机名查看步骤2git 远程分支名查看步骤3git 本地分支名查看示例演示 概述
在日常工作中将代码 git clone 本地之后或者使用repo init repo sync 之后不知道使用什么命令将修改好的代码git push 到服务器上本篇文章以自己工作中遇到的实际问题为例介绍下如何在不知道 git push 的具体参数的情况下一步一步查找到git push的正确命令。
git push 语法
我们都知道 push 命令的作用是将本地当前分支的代码推送到远程指定的分支上其命令的格式如下
git push 远程主机名 本地分支名:远程分支名使用 git push 命令将 本地分支名 的代码推送到 远程主机名 中的 远程分支名 上。
远程主机名 指的是你想要推送到哪个远程主机中在我们克隆一个项目的时候git 会自动帮我们把远程主机起名为 origin一般情况下是不会去修改这个名字的。本地分支名是本地分支的名字可以使用命令 git branch 来查看本地有哪些分支。远程分支名指的是远程主机中的分支名如果远程主机没有这个分支则会新创建一个。
步骤1git 远程主机名查看
使用 git remote 命令或者 git remote -v 命令
[10:45:53]samlinux (*^~^*) ~/sam/workbase/npu_code/device$ git remote
arm-valor
[10:47:31]samlinux (*^~^*) ~/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。
步骤2git 远程分支名查看
使用 git branch -vv 可以看到远程分支名为arm-val/arm_main
[10:54:31]samlinux (*^~^*) ~/sam/workbase/npu_code/device$ git branch -vv
* test b3f0b95 [arm-val/arm_main: ahead 1] device: compile: support npu device compile步骤3git 本地分支名查看
HEAD 表示一个特别的指针指向你正在工作的本地分支的指针可以当做是本地分支的别名。git 通过它可以知道当前工作区间在哪个分支。
refs/for 表示我们提交代码到服务器之后是需要经过 code review 之后才能进行merge 操作的而 refs/heads 是不需要的。
所以 git push 的命令为
git push 远程主机名 HEAD:refs/for/远程分支名示例演示
查看远程分支名
[10:45:26]samlinux (*^~^*) ~/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]samlinux (*^~^*) ~/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]samlinux (*^~^*) ~/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 samcodereview.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]samlinux (*^~^*) ~/sam/workbase/npu_code/device$ gitdir$(git rev-parse --git-dir); scp -p -P 29418 samcodereview.armtech.com:hooks/commit-msg ${gitdir}/hooks/[10:38:01]samlinux (*^~^*) ~/sam/workbase/npu_code/device$ git commit --amend --no-edit
[uefi_test b3f0b95] device: compile: support npu device compileDate: Wed Dec 6 14:38:57 2023 08001 file changed, 3 insertions(), 3 deletions(-)修改后再次重推
[10:38:15]samlinux (*^~^*) ~/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 的命令。 TIPS: 遇到问题还是要多查查小时候学的口号“不懂就要问” 应该改为 “不懂就去查”… 在查找分析结束后自己最好复盘下。即便别人告诉你答案你还是不知其所以然