Git冲突:commit your changes or stash them before you can merge.

一、问题背景

今天用git pull来更新代码,遇到了下面的问题:

susanxiao:push_management jiangxingqi$ git pull origin master
From git.tv.sohuno.com:taotaoli/push_management
 * branch            master     -> FETCH_HEAD
error: Your local changes to the following files would be overwritten by merge:
	pom.xml
Please commit your changes or stash them before you merge.
Aborting

二、解决方案

1.stash

通常遇到这个问题,你可以直接commit你的修改;但我这次不想这样。

看看git stash是如何做的。

git stash

susanxiao:push_management jiangxingqi$ git stash
Saved working directory and index state WIP on master: 81e62a8 jiangxingqi:统计pushback库中push_temp表中的category数据量,并存入ms库push_total_data
git pull

susanxiao:push_management jiangxingqi$ git pull
Merge made by the 'recursive' strategy.
 .../vrs/service/pushpool/FilterRepeatService.java  |   8 +
 .../service/pushpool/FilterRepeatServiceImpl.java  |  49 +++
 .../vrs/service/pushpool/PushPoolServiceImpl.java  |   7 +-
 .../com/sohu/tv/vrs/dao/push/rw/MatchVideoDao.java |  12 +-
 .../java/com/sohu/tv/vrs/entity/MatchVideo.java    |  36 ++-
 .../pushpool/RepeatManageController.java           |  65 ++++
 .../common/mapper/MatchVideoDao.xml                |  39 +++
 .../src/main/webapp/WEB-INF/page/repeat/list.jsp   | 352 +++++++++++++++++++++
 8 files changed, 565 insertions(+), 3 deletions(-)
 create mode 100644 push_management_web/src/main/java/com/sohu/tv/vrs/controller/pushpool/RepeatManageController.java
 create mode 100644 push_management_web/src/main/webapp/WEB-INF/page/repeat/list.jsp
git stash pop

susanxiao:push_management jiangxingqi$ git stash pop

On branch master

Your branch is ahead of 'origin/master' by 2 commits.

  (use "git push" to publish your local commits)



Changes not staged for commit:

  (use "git add <file>..." to update what will be committed)

  (use "git checkout -- <file>..." to discard changes in working directory)



	modified:   pom.xml



Untracked files:

  (use "git add <file>..." to include in what will be committed)



	.DS_Store

	.gitignore

	push_management_basic/.settings/org.eclipse.wst.validation.prefs

	push_management_dao/.settings/org.eclipse.wst.validation.prefs

	push_management_task/.settings/org.eclipse.wst.validation.prefs

	push_management_task/src/main/java/com/sohu/tv/vrs/timer/push/PushTmpCategoryIsNullCnt.java

	push_management_web/src/main/webapp/WEB-INF/page/pushpool/dataList2.jsp

	push_management_web/src/test/java/com/sohu/tv/vrs/service/PushTmpTest.java



no changes added to commit (use "git add" and/or "git commit -a")

Dropped refs/stash@{0} (d36dac98bcad717b8684abbab73c7d4ffd05c680)

git push

susanxiao:push_management jiangxingqi$ git push
Counting objects: 65, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (43/43), done.
Writing objects: 100% (65/65), 5.41 KiB | 1.08 MiB/s, done.
Total 65 (delta 28), reused 0 (delta 0)
To git.tv.sohuno.com:taotaoli/push_management.git
   db3aa9c..8144cdd  master -> master
susanxiao:push_management jiangxingqi$ git stash list
susanxiao:push_management jiangxingqi$ 

git stash: 备份当前的工作区的内容,从最近的一次提交中读取相关内容,让工作区保证和上次提交的内容一致。同时,将当前的工作区内容保存到Git栈中。
git stash pop: 从Git栈中读取最近一次保存的内容,恢复工作区的相关内容。由于可能存在多个Stash的内容,所以用栈来管理,pop会从最近的一个stash中读取内容并恢复。
git stash list: 显示Git栈内的所有备份,可以利用这个列表来决定从那个地方恢复。
git stash clear: 清空Git栈。此时使用gitg等图形化工具会发现,原来stash的那些节点都消失了。

2.放弃本地修改,直接覆盖之

git reset --hard
git pull
相关文章
相关标签/搜索