文章目录
  1. 1. git to overwrite local files on pull
  2. 2. git to overwrite local files on pull

git to overwrite local files on pull

git someTrouble

git to overwrite local files on pull

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

The errors I’m getting are:

error: Untracked working tree file ‘public/images/icon.gif’ would be overwritten by merge.

How do I force git to overwrite them? The guy is a designer - usually I resolve all the conflicts by hand so the server has the most recent version that he just needs to update on his computer

–如果本地不想merge文件了,想直接用git仓库里最新的代码,则只要执行

git reset --hard origin/master 

git fetch downloads the latest from remote without trying to merge or rebase anything. Then thegit reset resets the master branch to what you just fetched.

或者(这个命令会将本地项目所有文件discard拿仓库最新覆盖掉):
ometimes just clean -f does not help. In case you have untracked DIRECTORIES, -d option also needed:

git reset --hard HEAD
git clean -f -d 

git pull

–如果要merge文件则如下
irst do a commit of your changes

 git add *
 git commit -a -m "auto dev server commit"

then fetch the changes and overwrite if there is a conflict

 git fetch origin master 

 git merge -s recursive -X theirs origin/master

—恢复本地删除的但还没有提交的文件
git checkout MainStoryboard.storyboard

—恢复文件到某个版本
_git log_命令显示从最近到最远的提交日志,我们可以看到3次提交,最近的一次是“append GPL”,上一次是“add distributed”,最早的一次是“wrote a readme file”。 如果嫌输出信息太多,看得眼花缭乱的,可以试试加上
–pretty=oneline参数:

$ git log --pretty=oneline
3628164fb26d48395383f8f31179f24e0882e1e0 append GPL
ea34578d5496d7dd233c827ed32a8cd576c5ee85 add distributed
cb926e7ea50ad11b8f9e909c05226233bf755030 wrote a readme file
$ git log
commit ea34578d5496d7dd233c827ed32a8cd576c5ee85
Author: Michael Liao <askxuefeng@gmail.com>
Date:   Tue Aug 20 14:53:12 2013 +0800

    add distributed
$ git reset --hard 3628164
HEAD is now at 3628164 append GPL

git reset —hard commitID aa.java (对单个文件回退到指定版本)
版本号没必要写全,前六位就可以了,Git会自动去找。

现在,你回退到了某个版本,关掉了电脑,第二天早上就后悔了,想恢复到新版本怎么办?找不到新版本的commit id怎么办?

在Git中,总是有后悔药可以吃的。当你用_$ git reset –hard HEAD^_回退到“add distributed”版本时,再想恢复到“append GPL”,就必须找到“append GPL”的commit id。Git提供了一个命令_git reflog_用来记录你的每一次命令:

$ git reflog
ea34578 HEAD@{0}: reset: moving to HEAD^
3628164 HEAD@{1}: commit: append GPL
ea34578 HEAD@{2}: commit: add distributed
cb926e7 HEAD@{3}: commit (initial): wrote a readme file

终于舒了口气,第二行显示“append GPL”的commit id是3628164,现在,你又可以乘坐时光机回到未来了。 

—恢复文件到上个版本(上一个版本就是HEAD^,上上一个版本就是HEAD^^)

$ git reset --hard HEAD^
HEAD is now at ea34578 add distributed
文章目录
  1. 1. git to overwrite local files on pull
  2. 2. git to overwrite local files on pull