简体   繁体   English

git 推送未显示在 github 上并且仍然 lfs 错误

[英]git push not showing on github and still lfs error

I recently made a new directory on my local and copied all my changes from another project using a different source control into this new directory.我最近在本地创建了一个新目录,并使用不同的源代码控制将我从另一个项目中所做的所有更改复制到了这个新目录中。

Inside the new directory I did在我做的新目录中

git remote add origin git@github.com/user/repo.git //ssh url to my empty Github Repo

Afterwards, I did git status then git add all and git commit.之后,我做了git status然后 git add all 和 git commit。 Finally I did git push and I kept getting an error about a large file not being able to push to Github.最后我做了git push ,我一直收到一个错误,说大文件无法推送到 Github。 For this I did git lfs install and git lfs track "*.[filename]" but this didnt seem to work so I just deleted it from my new directory.为此,我做了git lfs installgit lfs track "*.[filename]"但这似乎没有用,所以我只是从我的新目录中删除了它。 After deleting it, I did git status again and committed the deletions of these files.删除后,我再次做了git status并提交了这些文件的删除。 However, when I push, I still get the error about the large files and checking out the lfs tool.但是,当我推送时,我仍然会收到有关大文件的错误并检查lfs工具。 When I go into my new directory, the large files git is complaining about is not there anymore.当我 go 进入我的新目录时,抱怨的大文件 git 不再存在。

You might try resetting the repo back to before you first committed the large files:您可以尝试在首次提交大文件之前将 repo 重置为:

git reset HEAD~2 --soft

then get things sorted out, commit , and push again.然后把事情整理好, commit ,然后再次push

Another way to do it would be with filter-branch , as per the git man page:另一种方法是使用filter-branch ,根据 git 手册页:

Suppose you want to remove a file (containing confidential information or copyright violation) from all commits:假设您想从所有提交中删除一个文件(包含机密信息或侵犯版权):

 git filter-branch --tree-filter 'rm filename' HEAD

Reason this is happening is that, even though you have now removed those files, they still were part of that first commit.发生这种情况的原因是,即使您现在已经删除了这些文件,它们仍然是第一次提交的一部分。 Git wants to keep a full history of the repository (hey, that's one of reasons you want to use it, right?) and so it keeps those files as part of that commit history. Git 想要保留存储库的完整历史记录(嘿,这是您想要使用它的原因之一,对吗?),因此它将这些文件作为提交历史记录的一部分。

After deleting it, I did git status again and committed the deletions of these files.删除后,我再次做了 git status 并提交了这些文件的删除。 However, when I push, I still get the error about the large files and checking out the lfs tool.但是,当我推送时,我仍然会收到有关大文件的错误并检查 lfs 工具。 When I go into my new directory, the large files git is complaining about is not there anymore.当我 go 进入我的新目录时,抱怨的大文件 git 不再存在。

I assume you mean that you did git rm on the large file.我假设您的意思是您对大文件执行了git rm This removes the file from the current working directory and after you git commit adds a commit that shows the file was removed.这将从当前工作目录中删除文件,并且在您git commit后添加一个提交,显示文件已被删除。 However, the commit where you added the large file still remains in the history in your git repository .但是,您添加大文件的提交仍保留在 git 存储库的历史记录中 This means that when you git push , it will still try to push the commit that added the large file.这意味着当你git push时,它仍然会尝试推送添加大文件的提交。

If you added the large file recently, you can use git reset to reset your current branch to a commit before you added it.如果您最近添加了大文件,您可以在添加之前使用git reset将当前分支重置为提交。 Note that this will remove all changes since that commit.请注意,这将删除自该提交以来的所有更改。 If you have other changes you want to keep, then you need to use git filter-branch or a 3rd party tool.如果您有其他想要保留的更改,则需要使用git filter-branch或第 3 方工具。 How to remove/delete a large file from commit history in Git repository? 如何从 Git 存储库中的提交历史记录中删除/删除大文件? has a very good description about how to do this.对如何执行此操作有很好的描述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM