簡體   English   中英

如何強制 git apply 覆蓋未跟蹤的文件?

[英]How can I force git apply to overwrite untracked files?

我有一個應用補丁的腳本,有時它會因任何原因而失敗(在我的情況下是文件權限)。 我想在解決問題后再次運行腳本,但是可能會有上次 git apply 嘗試的剩余文件。

我不想運行git clean ,這會丟掉我想保留的其他文件。 我只想替換那些受補丁影響的未跟蹤文件。

我的腳本:

for SITE in $SITES
do
  echo "Updating $SITE ..."
  cd /home/klausi/web/$SITE
  chmod u+w sites/default
  git fetch
  git reset --hard origin/master
  git apply --index /home/klausi/web/7.33.patch
  git commit -m "Updated Drupal core to 7.33."
  git push
done

當我再次運行時,我得到:

error: misc/throbber-active.gif: already exists in working directory
error: misc/throbber-inactive.png: already exists in working directory
error: modules/simpletest/tests/themes/test_theme/templates/node--1.tpl.php: already exists in working directory

所以像git apply --force這樣的東西會很好。

您可以嘗試幾個選項。

  • 當應用 run git apply --check to 而不是應用補丁時,看看它是否可以應用,如果不能中止它。 如果檢查返回正常,則繼續並正常運行git apply
  • 當應用 run git apply --cached直接應用於索引但保持工作副本完好無損。 如果失敗,只需清除索引。 如果它有效,請繼續提交。

暫無
暫無

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

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