Git强制覆盖本地跟踪文件,但不覆盖本地未跟踪的文件 [英] Git force overwrite of local tracked files but not local untracked files

查看:1457
本文介绍了Git强制覆盖本地跟踪文件,但不覆盖本地未跟踪的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个名为 p1 的本地目录中工作,其中包含一个git仓库。在添加分支并在添加的分支上进行提交后,我创建了目录 p1 的副本,并将其命名为 p2 。我的目的是在目录 p2 中尝试合并和重新绑定(只是为了学习),同时从 p1 当我确定如何合并/重新绑定我的更改时。

然而,我不小心做了合并,然后从 p2 目录。这是好的,因为现在远程仓库有我的git项目的正确状态。



但是,我需要现在替换目录 p1中的内容以及远程回购中的内容。这样,目录 p1 将会是最新的。



当我进入目录<$ c $

  git 

pull
更新e07d50d..287ec08
错误:对以下文件的本地更改将被合并覆盖:
debug / external / subdir.mk
debug / makefile
debug / subdir.mk
input / parameters.cfg
main.cpp
请在提交您的更改或隐藏它们后再进行合并。
正在取消

现在,我已经找到了解决此问题的潜在解决方案,例如



<然而,我的问题是目录 p2 包含未跟踪的文件,当我从远程回购中拉出时,我不想删除这些文件

那么,我该如何从远程仓库中取出,覆盖我的本地追踪文件,而不删除本地未跟踪的文件?






注意:其中一个答案

解决方案

  git fetch 
git reset --hard origin / master


I was working in a local directory named p1 which contains a git repo. After adding a branch and making a commit on the added branch, I made a copy of the directory p1 and called it p2. My intention was to play around with merging and rebasing (just to learn) in directory p2, while pushing to the remote repo from p1 when I determined how I wanted to merge/rebase my changes.

However, I accidentally did the merging and then pushed to the remote repo from the p2 directory. This is OK, because now the remote repo has the correct state of my git project.

However, I need to now replace what's in directory p1 with what's in the remote repo. That way, directory p1 will be up-to-date.

When I go into directory p1 and try to pull from the remote repo, here is what I get:

git pull
Updating e07d50d..287ec08
error: Your local changes to the following files would be overwritten by merge:
    debug/external/subdir.mk
    debug/makefile
    debug/subdir.mk
    input/parameters.cfg
    main.cpp
Please, commit your changes or stash them before you can merge.
Aborting

Now, I have found potential solutions to this problem, such as this.

The problem in my case, however, is that directory p2 contains untracked files that I do NOT want deleted when I pull from the remote repo.

So, how can I pull from the remote repo, overwriting my local tracked files, without deleting local untracked files?


Note: one of the answers here seems to be appropriate for me, but I'm not 100% certain.

解决方案

git fetch
git reset --hard origin/master

这篇关于Git强制覆盖本地跟踪文件,但不覆盖本地未跟踪的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆