簡體   English   中英

git merge 沒有來自無關分支的合並沖突

[英]git merge without merge conflicts from unrelated branch

我有一個在本地機器上損壞的 git 存儲庫。 為了解決我的問題,我刪除了本地機器上的 git 文件並運行git init 然后我運行git commit -m "fixing git" 我的fix_git分支有我的最新代碼,我想拉入我的遙控器並將其與我的develop分支合並。 我繼續並重置了我的遠程來源。 然后我嘗試拉我的開發分支並收到以下錯誤

致命的:拒絕合並不相關的歷史

然后我嘗試了以下git pull origin cleanup --allow-unrelated-histories它創建了許多合並沖突,以便能夠通過。 此外,我打算保留我在本地機器上所做的每一個更改。 我將如何修復它以便我的遙控器進行更改並保留我的歷史記錄?

定義:

(location alpha) is my local repo file path with my .git file that got corrupted
(location beta)  is a new file path

並不是說這是最好的解決方案。 我花了4個小時才得出這個結論。

  1. 我只是將git clone到與我的本地存儲庫(位置 alpha)分開的另一個位置(位置 beta)。
  2. 切換到我在位置測試版中新克隆的 repo 中的開發分支。
  3. 刪除了除 .git 文件之外的所有文件。
  4. 然后我將所有文件從 alpha 位置復制到 beta 位置。
  5. git add . git commit -m "solving git problems"
  6. 去我的本地倉庫並運行git pull -f

我會這樣做:

git init .
git add .
git commit "what I want as latest"
git remote add some-remote url-to-repo-with-the-project
git fetch some-remote
git reset --soft some-remote/some-branch
# all changes are in index
git commit -m "Latest changes"

就是這樣。

暫無
暫無

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

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