簡體   English   中英

Git藏匿索引沖突

[英]Git stash keeping index conflict

我需要創建預提交鈎子來對項目進行一些“健全性測試”(主要檢查部署是否會順利進行)。 因為我只需要測試將要提交的更改,所以我需要在運行測試之前存儲非暫存的更改,並在執行此操作后彈出隱藏的更改。 但是存在一個問題,因為在以下情況下隱藏和索引之間可能會發生沖突:

假設我有一個名為testfile的文件,其內容如下:

first line
second line
third line

現在,我將在第二和第三之間添加一條線

first line
second line
second and a half line
third line

並運行git add這樣它就會上演。

現在,我將在上一行之后添加下一行,以便文件看起來像這樣

first line
second line
second and a half line
second and three quarters line
third line

因此,現在提交第一行和第二行,暫存第二個和一半,未暫存第二季度和四分之三,並提交第三行。

讓我們直接說清楚。 現在,當我運行git stash --keep-index ,然后執行測試並嘗試運行git stash pop ,結果如下:

Auto-merging testfile
CONFLICT (content): Merge conflict in testfile

文件內容如下所示:

first line
second line
second and a half line
<<<<<<< Updated upstream
=======
second and three quarters line
>>>>>>> Stashed changes
third line

我不知道如何在運行測試后重新應用隱藏的更改並避免這種類型的沖突。 我很高興為此指出正確的方向。

如果您希望將版本保存在存儲庫中( --theirs引用了該版本),則基本上需要git checkout --theirs (用於沖突文件)。

然后git reset HEAD從索引中刪除更改(由於沖突而在此處添加),最后git stash drop

如果有一個選項git-stash pop可以更好地處理此問題,那就太好了,因為這通常是您想要的。

暫無
暫無

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

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