我有一个主分支“dev”,我基于dev checkout 了一个分支“A”。下面是我采取的步骤:
1.在A上做修改,提交,然后推送并合并到dev。
1.已在服务器上删除。
1.在局部A上做了一些改动。
1.我尝试将本地A推送到服务器。即在分支A上执行git push --force
1.我发现服务器上的dev被我的本地dev强制更新了。
我的问题是,如果我在本地A分支上做了git push --force
,为什么dev是由我的本地dev更新的?
# BSDC-587_For_EMC_test has been merged to dev on server, and deleted on server
# Made some modifications and commit
$ git status
On branch BSDC-587_For_EMC_test
Your branch is ahead of 'dummy-ondemand/dev' by 5 commits.
(use "git push" to publish your local commits)
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: ../rtos/ssp/app/svc/config/AmbaCamCtrl.c
modified: ../rtos/ssp/app/svc/main/AmbaOpModeCtrlTask.c
Untracked files:
(use "git add <file>..." to include in what will be committed)
pkg/network_turnkey/source/usr/local/share/script/emc_download.sh
../rtos/mcu_image/bsd_mcu.bin
no changes added to commit (use "git add" and/or "git commit -a")
$ git add ../rtos/ssp/app/svc/config/AmbaCamCtrl.c
$ git add ../rtos/ssp/app/svc/main/AmbaOpModeCtrlTask.c
$ git branch
* BSDC-587_For_EMC_test
dev
$ git commit -m "BSDC-578 add network checking and downloading"
[BSDC-587_For_EMC_test 85f42e7] BSDC-578 add network checking and downloading
2 files changed, 33 insertions(+), 4 deletions(-)
// Try to push local branch to server, but it seems like git try to push dev branch
$ git push
To ssh://[email protected]/dummy-ondemand/tsdk-code.git
! [rejected] dev -> dev (fetch first)
error: failed to push some refs to 'ssh://[email protected]/dummy-ondemand/tsdk-code.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ cd ..
$ git pull
remote: Counting objects: 148, done.
remote: Compressing objects: 100% (148/148), done.
remote: Total 148 (delta 132), reused 0 (delta 0)
Receiving objects: 100% (148/148), 157.20 KiB | 0 bytes/s, done.
Resolving deltas: 100% (132/132), completed with 53 local objects.
From ssh://bitbucket.org/dummy-ondemand/tsdk-code
b2de179..9a75859 dev -> dummy-ondemand/dev
* [new branch] BSDC-592_store_IMSI_to_flash_at_boot -> dummy-ondemand/BSDC-592_store_IMSI_to_flash_at_boot
+ 07459ca...531ec19 BSDC_faster_time_to_first_picture -> dummy-ondemand/BSDC_faster_time_to_first_picture (forced update)
Auto-merging rtos/ssp/app/svc/main/AmbaOpModeCtrlTask.c
CONFLICT (content): Merge conflict in rtos/ssp/app/svc/main/AmbaOpModeCtrlTask.c
Recorded preimage for 'rtos/ssp/app/svc/main/AmbaOpModeCtrlTask.c'
Automatic merge failed; fix conflicts and then commit the result.
$ git status
On branch BSDC-587_For_EMC_test
Your branch and 'dummy-ondemand/dev' have diverged,
and have 6 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
You have unmerged paths.
(fix conflicts and run "git commit")
Changes to be committed:
modified: rtos/bsp/trailcam/bsp.c
modified: rtos/bsp/trailcam/ringbuffer.c
modified: rtos/bsp/trailcam/ringbuffer.h
modified: rtos/ssp/app/svc/AmbaUserSysCtrl.c
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: rtos/ssp/app/svc/main/AmbaOpModeCtrlTask.c
Untracked files:
(use "git add <file>..." to include in what will be committed)
ambalink_sdk_4_9/pkg/network_turnkey/source/usr/local/share/script/emc_download.sh
rtos/mcu_image/bsd_mcu.bin
$ vi rtos/ssp/app/svc/main/AmbaOpModeCtrlTask.c
$ git add rtos/ssp/app/svc/main/AmbaOpModeCtrlTask.c
$ git commit
Recorded resolution for 'rtos/ssp/app/svc/main/AmbaOpModeCtrlTask.c'.
[BSDC-587_For_EMC_test a46f1b9] Merge branch 'dev' of ssh://bitbucket.org/dummy-ondemand/tsdk-code into BSDC-587_For_EMC_test
ldy2534@ubuntu:~/Project/project_mcu/context/tekdev/tsdk-code$ git status
On branch BSDC-587_For_EMC_test
Your branch is ahead of 'dummy-ondemand/dev' by 7 commits.
(use "git push" to publish your local commits)
Untracked files:
(use "git add <file>..." to include in what will be committed)
ambalink_sdk_4_9/pkg/network_turnkey/source/usr/local/share/script/emc_download.sh
rtos/mcu_image/bsd_mcu.bin
nothing added to commit but untracked files present (use "git add" to track)
$ git branch
* BSDC-587_For_EMC_test
dev
ldy2534@ubuntu:~/Project/project_mcu/context/tekdev/tsdk-code$ git rebase dev
First, rewinding head to replay your work on top of it...
Applying: BSDC-587 EMC test wifi working version
Applying: BSDC-587 improve network connection
Applying: BSDC-587 tidy up code
Applying: BSDC-578 add more comments
Applying: BSDC-587 modifications according to review
Applying: Merged in BSDC-510_fix_x_uart_lost_messages (pull request #178)
Applying: Merged in BSDC-587_For_EMC_test (pull request #177)
Using index info to reconstruct a base tree...
M ambalink_sdk_4_9/pkg/bsd_app/tekipc_projectlink.cpp
M ambalink_sdk_4_9/pkg/bsd_app/tekipc_projectlink.h
M ambalink_sdk_4_9/pkg/bsd_app/xsmtp.cpp
M ambalink_sdk_4_9/pkg/bsd_app/xsmtp.h
M rtos/bsp/trailcam/devices.h
M rtos/ssp/app/svc/bsd_app/tekipc_bsd.cpp
M rtos/ssp/app/svc/bsd_app/tekipc_bsd.h
M rtos/ssp/app/svc/config/AmbaCamCtrl.c
M rtos/ssp/app/svc/format/AmbaMovMuxer.c
M rtos/ssp/app/svc/main/AmbaOpModeCtrlTask.c
M rtos/ssp/app/svc/main/AmbaPostProc.c
M rtos/ssp/app/svc/main/AmbaRecTask.c
M rtos/ssp/app/svc/main/DemoTask.c
M rtos/ssp/app/svc/main/inc/AmbaPostProc.h
M rtos/ssp/app/svc/main/inc/AmbaSVC.h
.git/rebase-apply/patch:86: trailing whitespace.
return false;
.git/rebase-apply/patch:665: trailing whitespace.
.git/rebase-apply/patch:588: new blank line at EOF.
+
.git/rebase-apply/patch:671: new blank line at EOF.
+
warning: 4 lines add whitespace errors.
Falling back to patching base and 3-way merge...
No changes -- Patch already applied.
Applying: BSDC-578 add network checking and downloading
$ tig
$ git status
On branch BSDC-587_For_EMC_test
Your branch and 'dummy-ondemand/dev' have diverged,
and have 7 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Untracked files:
(use "git add <file>..." to include in what will be committed)
ambalink_sdk_4_9/pkg/network_turnkey/source/usr/local/share/script/emc_download.sh
rtos/mcu_image/bsd_mcu.bin
nothing added to commit but untracked files present (use "git add" to track)
$ git add ambalink_sdk_4_9/pkg/network_turnkey/source/usr/local/share/script/emc_download.sh
$ git commit -m "BSDC-578 add emc_download script"
[BSDC-587_For_EMC_test a0983d0] BSDC-578 add emc_download script
1 file changed, 5 insertions(+)
create mode 100755 ambalink_sdk_4_9/pkg/network_turnkey/source/usr/local/share/script/emc_download.sh
$ git push
To ssh://[email protected]/dummy-ondemand/tsdk-code.git
! [rejected] dev -> dev (non-fast-forward)
error: failed to push some refs to 'ssh://[email protected]/dummy-ondemand/tsdk-code.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
$ git push --force
Total 0 (delta 0), reused 0 (delta 0)
remote:
remote: Create pull request for dev:
remote: https://bitbucket.org/dummy-ondemand/tsdk-code/pull-requests/new?source=dev&t=1
remote:
To ssh://[email protected]/dummy-ondemand/tsdk-code.git
+ 9a75859...b2de179 dev -> dev (forced update)
$ git branch
* BSDC-587_For_EMC_test
dev
字符串
2条答案
按热度按时间eh57zj3b1#
正如你所看到的,在BSDC-587_For_EMC_test分支旁边有一个星号。当你执行git pull时,它也从服务器上拉取了dev分支。如果你要这样做:
字符串
回到你的代码,我想你会发现它根本没有从你的本地分支更新。
yyyllmsg2#
在第一个
git status
中,它显示:字符串
马上就有问题了。您的本地分支将
dummy-ondemand/dev
设置为它的上游分支。这意味着(默认情况下)任何git push
命令(强制或其他)都将尝试更新dummy-ondemand/dev
。很明显,这不是你想要发生的,如果不知道你是如何创建这个分支的,也不知道你所做的全部历史,你就不可能说出你是如何进入这个状态的。
修复当前问题
git checkout BSDC-587_For_EMC_test
-切换到正确的分支git branch --unset-upstream
-删除与dev
的当前上游关联git push -u dummy-ondemand BSDC-587_For_EMC_test
-在远程dummy-ondemand
上创建分支BSDC-587_For_EMC_test
,并将本地上游设置为其现在
git push
不会导致dummy-ondemand/dev
的更改。