git解決error: Your local changes to the following files would be overwritten by merge

解決error: Your local changes to the following files would be overwritten by merge

在項目裏咱們通常都會把本身第一次提交的配置文件忽略本地跟蹤php

1html

[Sun@webserver2 demo]$ git update-index --assume-unchanged <filename>git

可是項目裏的其餘人若是不當心把該配置文件修改push到遠程倉庫以後,咱們git pull代碼的時候就會報錯web

1thinkphp

2vim

3spa

4.net

53d

6code

7

8

9

10

11

12

13

[Sun@webserver2 demo]$ git add .

[Sun@webserver2 demo]$ git commit -m 'update:index.php'

[master f8a7428] update:index.php

 file changed, 1 insertion(+), 1 deletion(-)

[Sun@webserver2 demo]$ git pull

remote: Counting objects: 5, done.

remote: Compressing objects: 100% (2/2), done.

remote: Total 3 (delta 1), reused 0 (delta 0)

Unpacking objects: 100% (3/3), done.

From git.oschina.net:sunzmit/thinkphp

   1bc9485..c63dff3  master     -> origin/master

error: Your local changes to the following files would be overwritten by merge:

    config.ini

大意是:您的本地更改的文件將被合併覆蓋。並指出了會被覆蓋的文件

解決方法:

1.撤銷本地對文件的忽略

1

[Sun@webserver2 demo]$ git update-index --no-assume-unchanged config.ini

2.從最近的一次提交中讀取內容,備份當前的工做區的內容,將當前的工做區內容保存到Git棧中

1

2

3

[Sun@webserver2 demo]$ git stash

Saved working directory and index state WIP on master: f8a7428 update:index.php

HEAD is now at f8a7428 update:index.php

3.pull遠程倉庫代碼

1

2

3

4

[Sun@webserver2 demo]$ git pull

Merge made by the 'recursive' strategy.

 config.ini | 2 +-

 file changed, 1 insertion(+), 1 deletion(-)

4.從Git棧中讀取最近一次保存的內容,恢復工做區的相關內容

1

2

3

[Sun@webserver2 demo]$ git stash pop

Auto-merging config.ini

CONFLICT (content): Merge conflict in config.ini

5.修改合併

1

2

3

4

5

6

7

8

[Sun@webserver2 demo]$ vim config.ini

<<<<<<< Updated upstream

This is a test file!!!!!!!!!!!!!!!!

=======

This is a test file

>>>>>>> Stashed changes

[Sun@webserver2 demo]$ cat test.txt

This is a test file

<<<<<<< Updated upstream到=======中是從遠程倉庫pull下來別人的內容,=======到>>>>>>> Stashed changes中是咱們本地文件內容,如今咱們能夠刪除其餘,只保留本身的內容This is a test file

6.把文件回覆到最新提交的版本,會保留修改內容

1

2

3

4

5

[Sun@webserver2 demo]$ git reset HEAD config.ini

Unstaged changes after reset:

M config.ini

[Sun@webserver2 demo]$ cat test.txt

This is a test file

7.再次忽略本地跟蹤,完成!

1

[Sun@webserver2 demo]$ git update-index --assume-unchanged config.ini

8.最後不要忘記清除Git棧的備份

1

[Sun@webserver2 demo]$ git stash drop

本文永久地址:http://blog.it985.com/10665.html
本文出自 IT985博客 ,轉載時請註明出處及相應連接。


God, Grant me the SERENITY, to accept the things I cannot change, COURAGE to change the things I can, and the WISDOM to know the difference.

相關文章
相關標籤/搜索