The following untracked working tree files would b

2019-01-29 14:59发布

On my branch I had some files in .gitignore

On a different branch those files are not.

I want to merge the different branch into mine, and I don't care if those files are no longer ignored or not.

Unfortunately I get this:

The following untracked working tree files would be overwritten by merge

How would I modify my pull command to overwrite those files, without me having to find, move or delete those files myself?

10条回答
劳资没心,怎么记你
2楼-- · 2019-01-29 15:48

You can try command to clear the untracked files from the local

git 2.11 and newer

git clean  -d  -f .

older git

git clean  -d  -f ""

where -d can be replace with following:

  • -x means ignored files are also removed as well as files unknown to git.

  • -d means remove untracked directories in addition to untracked files.

  • -f is required to force it to run.

here is the link that can be helpful as well.

查看更多
够拽才男人
3楼-- · 2019-01-29 15:49

git merge -f does not exit, but git checkout -f does.

git checkout -f donor-branch
git checkout receiving-branch
git merge donor-branch

This works because you make Git force-checkout the other branch, and thereby force-replace the untracked files with their tracked versions. If you then checkout back to your original branch the tracked files disappear, like in every checkout where files don't exist in the destination branch.

You mention a pull command in your answer. Pull is nothing but git fetch (acquire the remote history) + an automatic merge of the upstream branch; if you precede the solution above with a git fetch, and merge the upstream branch, the steps will look as follows.

git fetch origin
git checkout -f origin/mybranch
git checkout mybranch
git merge origin/mybranch
查看更多
啃猪蹄的小仙女
4楼-- · 2019-01-29 15:50

You can try that command

git clean -df
查看更多
狗以群分
5楼-- · 2019-01-29 16:00

If this is a one-time operation, you could just remove all untracked files from the working directory before doing the pull. Read How to remove local (untracked) files from the current Git working tree? for information on how to remove all untracked files.

Be sure to not accidentally remove untracked file that you still need ;)

查看更多
登录 后发表回答