取消文件链接失败。我应该再试一次吗?

发布于 2024-10-07 00:30:58 字数 168 浏览 0 评论 0原文

我的本地 git 存储库中的一个文件出现问题。当我尝试更改分支时,它会说:

Unlink of file 'templates/media/container.html' failed. Should I try again? (y/n)

这意味着什么?

Something wrong is going on with one of the files in my local git repository. When I'm trying to change the branch it says:

Unlink of file 'templates/media/container.html' failed. Should I try again? (y/n)

What could that mean?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

最单纯的乌龟 2024-10-14 00:30:58

这可能意味着另一个程序正在使用该文件,这会阻止 git 在您尝试更改分支时将文件“移入”或移出工作目录。

我在 Windows Vista 上发生过这种情况,其中 eclipse 是“使用”该文件的程序。该文件可能实际上并未在 Eclipse 中打开,但可能已由 Eclipse 运行的进程打开。

在这种情况下,请尝试在可能使用过该文件的任何应用程序中关闭该文件。如果这不起作用,请完全退出可能打开该文件的所有应用程序。

This could mean that another program is using the file, which is preventing git from "moving" the file into or out of the working directory when you are attempting to change branches.

I have had this happen on Windows Vista where eclipse is the program "using" the file. The file may not be actually open in eclipse but may have been opened by a process run by eclipse.

In this event, try closing the file in any applications that might have used it. If that doesn't work, completely exit any applications which may have opened the file.

说不完的你爱 2024-10-14 00:30:58

我遇到了这个问题并通过命令解决了它:git gc
上面的命令删除临时文件和不必要的文件。 (垃圾收集器。)

I had this issue and solved it by the command : git gc
The above command remove temp and unnecessary files. (Garbage collector.)

情何以堪。 2024-10-14 00:30:58

这里的这个解决方案对我有用:

这是 Windows 特定的答案,因此我知道它与您无关...我只是为了将来的搜索者的利益而将其包含在内。

就我而言,这是因为我从非提升的命令行运行 Git。 “以管理员身份运行”为我解决了这个问题。

this solution from here worked for me:

This is a Windows specific answer, so I'm aware that it's not relevant to you... I'm just including it for the benefit of future searchers.

In my case, it was because I was running Git from a non-elevated command line. "Run as Administrator" fixed it for me.

情丝乱 2024-10-14 00:30:58

我在执行 git pull 时遇到了这个问题。

我尝试了 git gc 并解决了我的问题。

I encountered this issue while doing a git pull.

I tried git gc and it resolved my problem.

各空 2024-10-14 00:30:58

就我而言,没有进程接触文件或目录。如果路径很长,由于操作系统限制(Windows),可能会发生这种情况。尝试在全局 git 配置中启用长路径支持标志,如下所示:

git config --global core.longpaths true

或者尝试设置是/否答案标志(如果它对您来说不冲突)

set GIT_ASK_YESNO=false

如果路径太长,我还没有找到成功的解决方案。

In my case there are no processes touching the file or directory. Maybe it happens if the path is very long, because an operating system restriction (windows). Try enabling the longpath support flag in the global git configuration as indicated below:

git config --global core.longpaths true

or try to setting the yes/no answer flag if it is not conflictive for you

set GIT_ASK_YESNO=false

If the path is too long, I've not found a successful solution.

最佳男配角 2024-10-14 00:30:58

这可能对某人有用;如果上述所有方法都不适合您,请按照以下步骤操作:

  1. 关闭您的 IDE(我的是 Eclipse,不确定它是否适用于 Intellij 和其他)或任何其他可能使用 git 的应用程序。

  2. 从命令行打开 git(在我的例子中我有 git bash)并运行 git gc 正如其他人提到的。

这对我来说很神奇。

This might be useful for someone; if all the above didn't work for you, follow these steps:

  1. Close your IDE (mine was Eclipse, not sure if it applies to Intellij and others) or any other app that might be using git.

  2. Open git from the command line (in my case I had git bash) and run git gc as mentioned by others.

This did the magic for me.

迷乱花海 2024-10-14 00:30:58

当我使用 gitkraken 和命令提示符时,我遇到了同样的问题。然后我运行 git gc 命令它解决了我的问题。所以我很高兴并想分享一些可能有帮助的观点。

git gc 会做什么?

git gc 删除可能是通过先前调用 git add 创建的无法访问的对象。

何时运行 git gc ?

doc 开始,鼓励用户在每个存储库中定期运行此任务,以维护良好的磁盘空间利用率和良好的运行性能。

如何使其自动配置?

一些 git 命令可能会自动运行 git gc;有关详细信息,请参阅下面的 --auto 标志。如果您知道自己在做什么,并且只想永久禁用此行为而不需要进一步考虑,则只需执行以下操作

git config --global gc.auto 0

As i am using gitkraken and command prompt, i ran into the same issue. And then i run git gc command it resolved my problem. So i am happy and want share some of the points which might be helpful.

What git gc will do ?

git gc removing unreachable objects which may have been created from prior invocations of git add.

When to run git gc?

From doc, users are encouraged to run this task on a regular basis within each repository to maintain good disk space utilization and good operating performance.

How to make it auto-configurable?

Some git commands may automatically run git gc; see the --auto flag below for details. If you know what you’re doing and all you want is to disable this behavior permanently without further considerations, just do

git config --global gc.auto 0
不忘初心 2024-10-14 00:30:58

我在 Windows 7 上遇到了此类问题,结果是由于某些孤立的 git.exe 进程造成的。

要解决此问题,请打开任务管理器并终止所有 git.exe 进程。

由于 git 命令的生命周期很短,因此您通常不会在任务管理器中看到任何 git.exe。当它们出现时,通常意味着出现了问题,您应该终止这些进程。

I had this kind of issue on Windows 7 and it turned out to be due to some orphaned git.exe process.

To solve it, open Task Manager and kill all git.exe processes.

Since git commands are short-lived, you should normally never see any git.exe in Task Manager. When they are there, it usually means something is wrong, and you should kill those processes.

ぶ宁プ宁ぶ 2024-10-14 00:30:58

我尝试了 git gc 并解决了我的问题。

I tried git gc and it resolved my problem.

像极了他 2024-10-14 00:30:58

我能够通过以管理员身份打开 Powershell 并从那里解决这个问题
git checkout

I was able to solve this by opening Powershell as Administrator and from there
git checkout <branch_name>

郁金香雨 2024-10-14 00:30:58

在 Windows 8 上:
我运行了 git gc ,它说 git gc 已经在运行,我运行了 git gc --force ,垃圾收集器运行了。

然后我可以毫无问题地切换分支并合并,尝试 git gc --force 。

也许由于某种原因,gc 进程没有正常停止。

On Windows 8:
I ran git gc and it said git gc was already running, I ran git gc --force and the garbage collector ran.

I could then switch branches and merge without any issues, try git gc --force.

Perhaps the gc process didn't stop gracefully for one reason or another.

豆芽 2024-10-14 00:30:58

我在 Windows 中遇到这个问题。我关闭了 IDE (Android Studio) 并在 git shell 中选择了 YES。它起作用了。

I got this problem in Windows. I closed my IDE (Android Studio) and selected YES in git shell. It worked.

め七分饶幸 2024-10-14 00:30:58

就我而言(Win8.1,TortoiseGit 运行),正是名为“TortoiseSVN 状态缓存”的进程锁定了文件。

杀死它让我可以运行“git gc”而不再出现任何问题。
上面的进程是由TortoiseGit启动的,所以不需要手动重启它。

In my case (Win8.1, TortoiseGit running), it was the process called "TortoiseSVN status cache" that was locking the file.

Killing it allowed me to run "git gc" without any more problems.
The above process is fired up by TortoiseGit, so there is no need to manually restart it.

离鸿 2024-10-14 00:30:58

我在 /.git/objects/pack 文件夹中的 .tmp 文件遇到了这个问题。我认为在推送或拉取过程中出现了某些问题,因此我删除了这些临时文件并将 HEAD 重置为我的最后一次提交。不确定这是否建议,但它对我有用。另外 git count-objects -v 还给了我一个不属于 pack 文件夹的 .tmp 文件列表。

或者抑制 Windows 中的 y/n 消息 git open cmd.exe 并运行:

SETX GIT_ASK_YESNO false

参见此处:https://twitter.com/petercamfield/status/494805475733807104

I had this issue with .tmp files in /.git/objects/pack folder. I think something had failed during a push or pull, so I removed these temporary files and reset the HEAD to my last commit. Not sure if this is advised but it worked for me. Also git count-objects -v gave me a list of the .tmp files that didn't belong in the pack folder.

Or to suppress the y/n messages in windows git open cmd.exe and run:

SETX GIT_ASK_YESNO false

seen here: https://twitter.com/petercamfield/status/494805475733807104

栖竹 2024-10-14 00:30:58

我在执行“git pull”时遇到了同样的问题。我尝试了手动管理 git 命令“git gc”,它解决了我的问题。

I faced same issue while doing 'git pull'. I tried manual housekeeping git command 'git gc' and it resolved my problem.

百合的盛世恋 2024-10-14 00:30:58

在尝试了各种解决方案之后,终于 git clean -f 帮助了我。

编辑:我再次遇到这个问题几次 - 关闭所有依赖于 git 的进程似乎有帮助(如 gitbash、Eclipse IDE 等)

After trying various solutions finally git clean -f helped me.

EDIT: I hit the problem again few times - closing all processes dependent on git seems to help (like gitbash, Eclipse IDE, etc.)

蒗幽 2024-10-14 00:30:58

我在 Windows 中遇到了这个问题,您可能需要以管理员身份运行 git bash,然后执行所需的命令,这为我解决了这个问题。

I ran into this issue in Windows, you might want to run the git bash as an administrator and then perform the desire commands, that solved the issue for me.

白芷 2024-10-14 00:30:58

运行命令后,

git rm -rf foo.bar

我看到错误

Unlink of file 'foo.bar' failed. Should I try again? (y/n)

,因为另一个程序正在使用此文件。例如,当我在调试模型中运行Java Web应用程序或在服务器上运行Web应用程序时,我无法删除日志文件。关闭应用程序服务器(或关闭调试进程),重试

git rm -rf foo.bar

我看到文件已被删除。

After run command

git rm -rf foo.bar

I see error

Unlink of file 'foo.bar' failed. Should I try again? (y/n)

Because another program is using this file. For example, when I run Java web application in debug model or run web application on server, I can't delete log file. Turn off application sever (or turn off debug process), re-try

git rm -rf foo.bar

I see file has been deleted.

旧城空念 2024-10-14 00:30:58

为我工作,在 Windows 上尝试过:

停止您的服务器从 IDE 运行或关闭您的 IDE

Intellij/Ecllipse 或任何,它会工作。

Worked for me, Tried on windows:

Stop your server running from IDE or close your IDE

Intellij/Ecllipse or any, it will work.

北风几吹夏 2024-10-14 00:30:58

如果您的操作系统主机是类似 linux/unix 的,您可以运行 git gc --force 来停止使用 git 文件的文件处理程序,

否则如果您在 Windows 上工作,您可以停止通过任务管理器或进程管理器进行 git 进程。似乎有另一个 git 进程正在使用你的 git 文件。只需杀死 git 进程即可

if your os host is linux/unix-like, you can run git gc --force to stop the file handler which take use of git files,

else if you're working on windows, you can stop git process by Task Manager or Process Manager. It seems that there are another git process taking use of your git files. Just kill the git process

陪我终i 2024-10-14 00:30:58

我在同时运行 git Bash 和 Eclipse EGit 时遇到了这个问题。
解决方案:关闭Eclipse。正如 @khilo 提到的那样,运行 git gc 也不会造成伤害。

I ran into this issue running git Bash and Eclipse EGit at the same time.
Solution: close Eclipse. Also wouldn't hurt to run git gc as @khilo mentioned.

撩起发的微风 2024-10-14 00:30:58

如上所述,文件由其他东西保存。问题是该程序对我们来说并不可疑。
我试图在打开 GitKraken 的同时从控制台执行 git pull 。关闭 GitKraken 解决了这个问题。

As stated above, something else is holding the files. Thing is that program doesnt look suspicious for us.
I was trying to do a git pull from console, while having GitKraken opened. Closing GitKraken fixed the problem.

再浓的妆也掩不了殇 2024-10-14 00:30:58

如果您使用 Docker 并运行 Windows 10,您可能需要停止运行该文件的容器。要显示容器的状态,请运行

docker ps -a

要停止它们,只需运行

docker stop <容器名称或容器 id>

这对我来说很有效使用 .sh 文件运行我的本地文件

If you're using Docker and running Windows 10, you may want to stop the container(s) where the file may be running at. To show the statuses of your containers, run

docker ps -a

To stop them, simply run

docker stop <container name or container id>

This worked for me as I am running my local files using a .sh file

我还不会笑 2024-10-14 00:30:58

就我而言,我尝试从 GitKraken 的终端运行 git fetch --all 。我必须关闭 Gitkraken 并从 Windows 终端运行命令才能使其正常工作。

In my case, I was trying to run git fetch --all from within GitKraken's terminal. I had to close Gitkraken and run the command from Windows Terminal in order for it to work.

世态炎凉 2024-10-14 00:30:58

在上述答案似乎都不起作用之后,运行 git fetch -p 为我完成了这项工作。

https://git-scm.com/docs/git-fetch

After none of the above answers seemed to work, running git fetch -p did the job for me.

https://git-scm.com/docs/git-fetch

演出会有结束 2024-10-14 00:30:58

我尝试了此页面上的每一个提示,但没有任何帮助。我正在执行 git fetch ,而 git reset --hard origin/development 给了我 unkin 错误。我无法重置到最新的提交。

有用的是检查另一个分支,然后检查前一个分支。很奇怪,但它解决了问题。

I tried every single tip on this page and nothing helped. I was doing a git fetch and a git reset --hard origin/development gave me the unkink error. I couldn't reset to the latest commit.

What helped was checking out another branch and then checking out the previous branch. Very strange but it solved the problem.

生寂 2024-10-14 00:30:58

如果关闭 IDE 并运行此处列出的各种 git 命令不起作用,请尝试手动终止所有正在运行的 Java 进程。我有一个可能是 eclipse 遗留下来的 Java 进程,它以某种方式使配置文件保持打开状态。

If closing your IDE and running various git commands listed here won't help, try manually killing all running Java processes. I had a Java process probably left over from eclipse that somehow kept a configuration file open.

吖咩 2024-10-14 00:30:58

对于我的 Spring Boot 项目,我在尝试运行 git stash 时遇到了此错误。

解决方案是终止我机器上运行的所有 Java 进程。

For my Spring Boot project I ran into this errror when attempting to run git stash.

The solution was to killed all of the Java processes running on my machine.

梦初启 2024-10-14 00:30:58

在我的情况下,原因是我当天早些时候以管理员身份运行了 Visual Studio。当我去切换分支时发生了错误。

我使用 GitExtensions 并以普通用户身份运行它,并且在以管理员身份运行时(以管理员身份运行,但仍然是我)无法访问 VS 创建的文件。这对我来说是原因的根源。我不知道为什么会发生这种情况,因为我经常在我的主要开发环境上以管理员身份运行 VS,并且以前没有遇到过这个问题。但今天由于某种原因,上述场景导致 VS 在该会话期间生成的任何文件都不可编辑...您可以读取它们,但不能更改或删除它们,这正是切换分支时 Git 要做的事情。

为了解决 Git 的问题,我必须以管理员身份启动 Windows 资源管理器并获得所有权并重新授予自己对有问题的文件和目录的权限。我不完全理解为什么会这样,因为我也以管理员身份运行资源管理器,但确实如此。

您可以单独对文件执行此操作,但我最终对分支的根文件夹执行此过程。

所以我解决问题的具体步骤是:
转到Windows资源管理器中的分支顶部,
右键单击目录的属性,
选择安全选项卡,
高级选项可打开“高级安全设置”对话框,
选择顶部的更改所有权(它可能显示您已经拥有它),
我重新选择了自己。
然后它会返回到“高级安全设置”对话框,请记住选中底部的“替换所有对象...”框
然后点击应用
系统循环遍历每个文件和文件夹,修复所有权,这为我解决了问题。

对我来说,它锁定了我的迁移文件夹,不允许我切换分支...所以我最初只是修复了该目录和子树,这允许我切换分支,但我已经关闭了 VS 试图解决问题。当我重新打开VS时,我没有以管理员身份运行VS,我发现现在无法编译解决方案!这是相同\相似的问题。它无法编译解决方案,因为所有 obj 目录现在都不可编辑...所以当我执行上述步骤时,一切又恢复正常了。

希望这对某人有帮助...;)

In my situation the cause was that I had ran Visual Studio as an administrator earlier in the day. When I went to switch branches the error occurred.

I use GitExtensions and I run it as a regular users and files created by VS while running as an administrator ( run as Administrator, still me though) were not accessible. This was the root of the cause for me. I'm not sure why it happened in this situation because I regularly run VS as administrator on my primary development environment and have not experienced this problem before. But for some reason today the above scenario caused any files generated by VS during that session to be un-editable...you can read them, but not change or delete them and that is exactly what Git is going to do when you switch branches.

To resolve the problem for Git I had to start windows explorer as administrator and take ownership and re give myself permissions to files and directories in question. I don't fully understand why this as I was running explorer as Administrator too but it did.

You can do this for the files individually but I ended up doing this process for the root folder of the branch.

So the exact steps I did to fix the problem are:
Went to the top of the branch in windows explorer,
right clicked properties of the directory,
select the security tab,
advanced options which opens the Advanced Security Settings dialog,
Selected change ownership at the top (it might show you already own it),
I re-selected myself.
Then it returns you to the 'Advanced Security Settings' dialog, at the bottom of remember to check the box 'Replace all object...'
Then click apply
The system cycles through each file and folder fixing ownership and that resolved the problem for me.

For me it had locked out my migrations folder and wouldn't let me switch branches...so I originally just fixed that directory and sub tree which allowed me to switch branches but I had closed VS trying to resolved the issue. When I reopened VS I did not run VS as the Administrator and I found that could not compile the solution now! It was the same\similar issue. It could not compile the solution as all of the obj directories were now non editable... so that is when I did the above steps and all was good again.

Hope this helps someone... ;)

猛虎独行 2024-10-14 00:30:58

正如上面的答案中提到的,是的文件可能必须被其他java进程使用,摆脱这个的简单方法是,只需杀死所有java进程然后执行git pull我这样做了,它有效为我。

对于 Windows 杀死所有 java 进程:

taskkill /F /IM java.exe

对于 Linux 杀死所有 java 进程:

kill -9 `pidof java`

As mentioned in the above answers, yes file must be used maybe by other java processes, simple way to get rid-off this is, just kill all java processes then execute git pull I did this, it works for me.

For windows kill all java processes:

taskkill /F /IM java.exe

For Linux kill all java processes:

kill -9 `pidof java`
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文