Git推送忽略的文件

时间:2019-01-18 13:35:39

标签: git gitignore

我在本地的yii2框架中建立了一个在线项目,并开始使用Git维护代码。几天后,我决定忽略一些文件和文件夹,例如“供应商,运行时和上载”文件夹。我现在有3-5个git分支。我还在Github网站上创建了一个存储库,用于在线保存更改。但是,所有被忽略的文件和目录都被推送到GitHub。目录的总大小(不包括.git目录)约为632MB。 “ .git”目录本身为1.3 GB。

我不想推送被忽略的文件和目录。

我使用以下命令从Git中删除了已添加的文件和文件夹。

git rm --cached <file> 
git commit -m "to save the changes"

但是,当我将文件推送到服务器时,它仍会推送已标记并忽略的文件和目录。

我想永久忽略我从所有Git分支添加到'.gitignore'文件中的文件和目录,还希望将其余文件推送到Git中。这是我的Git忽略文件的副本。每次我用 以下命令,它也会添加忽略的文件。

git add --all *

Git忽略文件:

# windows thumbnail cache
Thumbs.db

# composer itself is not needed
composer.phar

# composer vendor dir
/protected/vendor

# runtime dir
/protected/frontend/runtime/
/protected/backend/runtime/

#tempfiles
*~
/assets/**
/uploads/*
*.log

@Drubio这是目录结构:

/assests
/uploads
/protected
    /backend
       /runtime
       /<rest all the directory by default installed with yii2
    /common
    /frontend
       /runtime
       /<rest all the directory by default installed with yii2
    /vendor
    /console
    /environment

/.git
<few files here on root>
.gitignore
.htaccess

请帮助。

谢谢

2 个答案:

答案 0 :(得分:0)

so the problem is that your ignored files were already pushed to the remote branhc try the following set of commands:

to see the unwanted files:

git ls-files -ci --exclude-standard

remove the unwanted files

git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached

commit the changes

git commit -am "Removed unwanted files"

push the changes:

git push origin <branchname>

答案 1 :(得分:0)

Removing the unwanted files using git rm will remove those files from the file-tree in the commit where you removed them, but it will not make the Git repo smaller, since Git keeps a history of all the old commits still in the repository, and therefore of all the files they contain.

I don't want to go into how to rewrite the history to remove those large files - that's discussed at length here: How to remove/delete a large file from commit history in Git repository? but if you just started using Git for this project, it might be easiest to start with a fresh repo.

相关问题