簡體   English   中英

git push 不將本地更改提交到遠程存儲庫

[英]git push not submitting local changes to remote repository

我遵循了以下步驟。

$git log --oneline

commit5
commit4
commit3
commit2
commit1

$git checkout commit3

$git log --oneline
commit3
commit2
commit1

Now i made changes to few file.

$git add .
$git commit -m "commit6"
$git log --oneline
commit6
commit3
commit2
commit1

Now, i try to push these changes to remote repository.

$git push -f origin master


This command is not pushing my commit6 to the remote server.
I am getting the message everything up-to-date.

如何將 commit6 推送到遠程存儲庫。 我想要類似於我的本地狀態的遠程存儲庫狀態。

提前致謝。

$ git checkout commit3

我將在這里假設您使用原始哈希 ID 來簽出,例如:

$ git checkout fe3fec53a6
Note: switching to 'fe3fec53a6'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at fe3fec53a6 Merge branch 'bc/rev-list-without-commit-line'

請閱讀git checkout打印的所有文本。

現在我對幾個文件進行了更改。

 $ git add . $ git commit -m "commit6" $ git log --oneline commit6 commit3 commit2 commit1

您現在實際上已經創建了一個新的未命名分支。 這個新分支在你的新commit6處結束。

您現有的master分支保持不變。 它繼續以您在原始輸出中看到的現有commit5結束。

如何將 commit6 推送到遠程存儲庫。 我想要類似於我的本地狀態的遠程存儲庫狀態。

根據所討論的遠程存儲庫,這可能非常困難到不可能。 特別是,您的本地狀態使用分離的 HEAD 您可能無法將其他存儲庫置於 detached-HEAD 狀態。

可以將新提交發送到遠程存儲庫,但您可能希望使用分支名稱來執行此操作。 當您處於分離的 HEAD 模式時,您不在任何分支上 您根本沒有任何分支上進行 commit6。

您可以選擇放棄提交 4 和 5,而僅在本地使用提交 6 作為(本地) master分支的提示提交。 你可以嘗試設置遠程倉庫的master ,過在origin ,這個相同的狀態為好。 遠程存儲庫有權拒絕放棄提交 4 和 5,尤其是在您不擁有遠程存儲庫的情況下。 如果您確實擁有遠程存儲庫,您可以進行設置,以便您可以丟棄那里的提交——但您沒有告訴我們是否是這種情況。

您可以選擇在本地向master添加一個新提交,以便commit7 (新提交)在commit5之后立即出現,並將此新提交及其文件發送到遠程存儲庫。 這比讓遠程存儲庫丟棄提交 4 和 5 的請求更有可能成功,因為 Git 旨在添加新提交而不丟棄現有提交。

您需要決定這些操作中的哪一個是最合適的(或者是否有比其中任何一個都更好的替代方法)。 如果您希望強制遠程存儲庫放棄提交,通常需要某種“強制推送”。 有數百個關於此的現有 StackOverflow 問題。

如果您對幾個 fies 進行了更改,那么您首先要做的就是不要

$git commit -m "commit6"

但是要使用git add file_name將文件添加到 stage 然后您可以創建一個提交並將其推送到遠程倉庫確保您已首先使用git remote將您的離線倉庫與遠程倉庫相關聯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM