2013-03-01 147 views
7

我有一個git問題,我想將分支合併到主服務器中,但拒絕合併,因爲它認爲我對文件進行了本地更改。執行狀態顯示沒有變化,並且區分文件不會產生任何結果。這裏的終端輸出:Git拒絕合併,因爲對未更改文件的更改

$ git checkout ProductsAndContents 
Switched to branch 'ProductsAndContents' 

$ git status 
# On branch ProductsAndContents 
nothing to commit (working directory clean) 

$ git checkout master 
Switched to branch 'master' 

$ git status 
# On branch master 
nothing to commit (working directory clean) 

$ git merge ProductsAndContents 
error: Your local changes to the following files would be overwritten by merge: 
    tests/unit/src/models/BrandTests.js 
Please, commit your changes or stash them before you can merge. 
Aborting 

任何幫助或建議將不勝感激!

+1

你有沒有設法將該文件放在'.git/info/exclude'文件或'.gitignore'文件中? – 2013-03-01 19:18:36

+2

[此答案](http://stackoverflow.com/a/12167041/166732)中的配置選項有幫助嗎? – asm 2013-03-01 19:20:13

+0

嗨安德魯,設置'core.trustctime'爲false似乎已經做到了。感謝您指點我正確的方向:) – 2013-03-04 15:03:11

回答

3

感謝Andrew Myers對我最初的問題的評論,我發現設置core.trustctimefalse解決了這個問題。

git config core.trustctime false 

關於inode更改時間不匹配的問題。我猜這是因爲回購站位於具有與我使用的文件系統不同的文件系統的計算機上的文件共享。

感謝您的所有建議!

-2

只因爲每個分支都沒有提交併不意味着它們是相同的。我有興趣使用

git diff 

可以恢復使用

git checkout -- tests/unit/src/models/BrandTests.js 
+3

'請提交您的更改或隱藏它們,然後才能合併.'暗示未提交的更改,不支持分支之間的差異 – 2013-03-01 19:18:17

+0

確實沒有更改提交,並且沒有未跟蹤的文件。正如我所提到的,差異產生零輸出。我很困惑。 – 2013-03-04 12:55:38

1

好已致力於爲回購修訂查看這兩個文件之間的差異,如果你有信心,你贏了請勿嘗試以下任何方式:

rm tests/unit/src/models/BrandTests.js 
git checkout -- tests/unit/src/models/BrandTests.js 

這應該重置任何使其認爲已發生更改的機制。如果它不起作用,那麼可以有其他人。

+0

感謝Trev的建議!我嘗試過,但不幸的是它仍然給出了同樣的錯誤。所以很奇怪...... – 2013-03-04 12:54:18

+0

我也遇到過這個問題,但是看起來'git stash'會拒絕看到修改過的文件。我手動將其備份,檢查出來並手動比較變化。有一個更好的方法... – 2014-06-02 15:37:50

+0

@PaulLammertsma不要忘記,一個'存儲'只不過是另一個提交,並有自己的散列。您可以像對待其他任何提交一樣對其進行操作。這留下了許多其他選擇。我剛剛發現以上是最快的。 – 2014-06-02 22:20:43

1

我猜想這是您的方案:

$ git checkout ProductsAndContents 
Switched to branch 'ProductsAndContents' 

分公司ProductsAndContents包含文件tests/unit/src/models/BrandTests.js,因此上述checkout創建它和/或確保它是最新的與特定提交請求。

$ git status 
# On branch ProductsAndContents 
nothing to commit (working directory clean) 

你還沒有做任何改變,並開始一個乾淨的工作目錄,所以這是很好的。

$ git checkout master 
Switched to branch 'master' 

這可以確保master上的最新提交中包含的所有文件在工作目錄中都是最新的。但是,它不會刪除或更新master中未包含的或被忽略的文件。在這裏,我假設master出於任何原因目前不包括有問題的文件。

$ git status 
# On branch master 
nothing to commit (working directory clean) 

同樣,你做任何的修改。事實上,這裏沒有提到該文件作爲未跟蹤文件,這可能意味着它被忽略(在.gitignore.git/info/exclude中)。 master不包含該文件,因此它不擔心它存在。

$ git merge ProductsAndContents 
error: Your local changes to the following files would be overwritten by merge: 
    tests/unit/src/models/BrandTests.js 
Please, commit your changes or stash them before you can merge. 
Aborting 

在這裏,您試圖在另一個分支合併希望引入一個文件master目前沒有,這是正常的罰款。但是,該文件存在於您的工作目錄中,並且git不想將不確定的內容保存在存儲庫中。正如其他地方所建議的那樣,您可以(假設您知道這是安全的),只需刪除該文件並重新嘗試合併即可。根據你提供的信息,我不是100%肯定這就是你在這裏;你可以運行這兩個命令來檢查該條件,雖然:

git ls-files master -- tests/unit/src/models/BrandTests.js 
git ls-files ProductsAndContents -- tests/unit/src/models/BrandTests.js 

如果我的猜測是正確的,第一個命令將不會顯示該文件存在,而第二個意志。然後檢查.gitignore.git/info/exclude以查看它是否被忽略(對於.gitignore,您可能需要檢查兩個分支上每個分支上存在的版本)。

+0

謝謝!不幸的是,該文件在兩個分支中,而不是在.gitignore或.git/info/exclude中。這裏的輸出: $ git ls-files master - tests/unit/src/models/BrandTests.js tests/unit/src/models/BrandTests.js $ git ls-files ProductsAndContents - tests/unit/src/models/BrandTests.js tests/unit/src/models/BrandTests.js – 2013-03-04 13:01:54