git 从git存储库合并后如何删除.orig文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12366150/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:34:29  来源:igfitidea点击:

How to delete .orig files after merge from git repository?

git

提问by maximus ツ

Some how .orig files are checked in my git repository during merge, which are now displayed in modified and un-tracked sector. But I don't want this files anymore in my repository. How to do that.

在合并期间如何在我的 git 存储库中检查 .orig 文件,这些文件现在显示在已修改和未跟踪的扇区中。但是我不想再在我的存储库中使用这些文件了。怎么做。

    modified:   Gemfile.lock.orig
    #   modified:   Gemfile.orig
    #   modified:   app/assets/images/bg_required.png.orig
    #   modified:   app/assets/javascripts/application.js.orig

    etc...

Any help will be appreciated.

任何帮助将不胜感激。

回答by TheChymera

Best solution in this case is to keep it simple and get rid of those files independently of git:

在这种情况下,最好的解决方案是保持简单并独立于 git 删除这些文件:

cd /your/repo/directory
find . -name '*.orig' -delete 

Alternatively, in Windows/PowerShell, you can run the following command

或者,在 Windows/PowerShell 中,您可以运行以下命令

cd \your\repo\directory
Get-ChildItem -Recurse -Filter '*.orig' | Remove-Item

回答by Amar

Try git cleanmore info you can find hereor here

尝试git clean更多信息,您可以在此处此处找到

回答by rowan

you can do:

你可以做:

git config --global mergetool.keepBackup false

For more info, refer to to Git mergetool generates unwanted .orig files

有关更多信息,请参阅Git mergetool 生成不需要的 .orig 文件

回答by Loken Makwana

You can ignore files using .gitignore

您可以使用 .gitignore 忽略文件

Just put *.orig in the list like shown here

只需将 *.orig 放入列表中,如下所示

https://help.github.com/articles/ignoring-files

https://help.github.com/articles/ignoring-files

for deleting current files you can create shell script and run from project folder like below

要删除当前文件,您可以创建 shell 脚本并从项目文件夹中运行,如下所示

for file in `find *.orig -type f -print`
do
   echo "Deleting file $file"
   git rm $file -f       
done

回答by Jeff Puckett

Unfortunately git cleandoesn't work for me because I have *.origadded to my global gitignore file, so they're ignored from clean as well. Even running git clean -xis no good because I don't want allof my ignored files getting deleted. git clean -iis helpful, but really I don't want to have to review each and every file.

不幸的是,git clean这对我不起作用,因为我已将其*.orig添加到全局 gitignore 文件中,因此它们也从 clean 中被忽略。即使运行git clean -x也不好,因为我不希望所有被忽略的文件都被删除。git clean -i很有帮助,但我真的不想检查每个文件。

However, we can use an exclude pattern and negate the match. Preview with this command:

但是,我们可以使用排除模式并否定匹配。使用此命令预览:

git clean -e '!*.orig' --dry-run

Then when you're confident, pass the forceflag to really delete them:

然后当你有信心时,传递force标志以真正删除它们:

git clean -e '!*.orig' -f

Based on leorleor's comment

基于leorleor 的评论

回答by linquize

git rm Gemfile.lock.origand the rest of the files you don't need. git commit --amend

git rm Gemfile.lock.orig以及您不需要的其余文件。 git commit --amend

To completely remove those blobs, git gc --prune=0 --aggressive

要完全去除这些斑点, git gc --prune=0 --aggressive

回答by Ueffes

For me git clean -fremoved all *.oig files. And keeps the ones that were already there before.

对我来说,git clean -f删除了所有 *.oig 文件。并保留之前已经存在的那些。

This is what it (almost) looked like after the merge:

这是(几乎)合并后的样子:

$ git status
On branch feature/xyz
Your branch is ahead of 'origin/feature/xyz' by 568 commits.
  (use "git push" to publish your local commits)

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

    .idea/codeStyles/
    .idea/misc.xml.orig

.idea/codeStyles/was already there before the merge as an untracked file. .idea/misc.xml.orig(and a lot more) had to be removed.

.idea/codeStyles/在合并之前作为未跟踪文件已经存在。.idea/misc.xml.orig(以及更多)必须被移除。

=> Using git clean -f:

=> 使用git clean -f

$ git clean -f
Removing .idea/misc.xml.orig

resulted in:

导致:

$ git status
On branch feature/xyz
Your branch is ahead of 'origin/feature/xyz' by 568 commits.
  (use "git push" to publish your local commits)

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

    .idea/codeStyles/

回答by fiorentinoing

you can simply do git status -s | grep "\.orig$" | awk '{print $2}' | xargs -n1 -r echo rm

你可以简单地做 git status -s | grep "\.orig$" | awk '{print $2}' | xargs -n1 -r echo rm

TL;DR;

TL; 博士;

git status -sallows you to get all modified/missing files in respect of the index

git status -s允许您获取有关索引的所有修改/丢失文件

grep "\.orig$"filter out files, keeping the ending by ".orig"

grep "\.orig$"过滤掉文件,以“.orig”结尾

awk '{print $2}'lists file name (skipping git information e.g. A, M, ??)

awk '{print $2}'列出文件名(跳过 git 信息,例如 A、M、??)

xargs -n1 -r echo rmprints remove commands on every arguments (-n1: one at a time and -r: skip when empty) just copy&paste the commands double-checking for files to remove.

xargs -n1 -r echo rm在每个参数上打印删除命令(-n1:一次一个,-r:空时跳过)只需复制并粘贴命令,仔细检查要删除的文件。

回答by veritas1

git rm <file>

git rm <file>

http://git-scm.com/docs/git-rm

http://git-scm.com/docs/git-rm

Also add files/directories you want to ignore to your .gitignore file.

还要将要忽略的文件/目录添加到 .gitignore 文件中。