GIT 存盤庫中有一個專案,該專案安裝在生產服務器中,但 GIT 未初始化。上個月有些人在生產服務器的源代碼中編輯了檔案,但那里沒有 GIT。我還沒有創建存盤庫或安裝在服務器上,但現在我想在生產服務器中安裝 GIT 并將現有源鏈接到 GIT 存盤庫并將現有源的更改提交到 GIT 存盤庫。
我嘗試將生產服務器的檔案復制到 mi PC 的本地目錄中,然后:
git init
git remote add origin https://.....git
當我運行git status它回傳:
On branch master
No commits yet
Untracked files:
...
...
我希望只出現不同的檔案,但絕對所有檔案都以紅色顯示未跟蹤。
我該怎么做?
提前致謝
uj5u.com熱心網友回復:
這會很棘手。一種基本方法可能是git clone ...獲取存盤庫的當前狀態,然后簡單地將所有檔案替換為生產服務器檔案的副本。
但是,這可能會將檔案還原為您不希望還原的舊版本(除了包括您實際想要的更改)。我不知道您的存盤庫有多大,所以我不知道這可能是一個多大的問題。對更改進行仔細的代碼審查可能會奏效。
完整步驟:
$ git clone ... [new_repo_name]
$ rm -rf new_repo_name/** # Deletes existing contents (will not delete .git folder) You can do this manually if you like
$ cp path/to/production/server/copy/** new_repo_name # Copy production server contents across (you can do this manually as an alternative)
$ cd new_repo_name
$ git checkout -b [branch_name] # Create a new branch
$ git add . # Mark everything as to be committed.
$ git commit -m "Replace everything with production server version."
$ git push --set-upstream origin branch_name # Push branch to origin
此時,您可以向您的主分支發出拉取請求,并仔細審查您看到的任何更改。您最終可能只想引入您看到的一些更改。祝你好運。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/435160.html
標籤:混帐
上一篇:從遠程倉庫有效地復制git作業樹
