git-推送时在repo中保留特定文件
推送时,我想在repo中保留一个文件 本地目录git-推送时在repo中保留特定文件,git,github,Git,Github,推送时,我想在repo中保留一个文件 本地目录 Dir ----file_1.css ----file_2.css ----file_3.css ----.gitignore Github回购协议 repo ----file_1.css ----file_2.css ----file_3.css ----preserve.css ----.gitignore 我的本地目录没有preserve.css文件。因此,当我提交并推送时,preserve.css文件在我的repo中被删除。但是,我想在
Dir
----file_1.css
----file_2.css
----file_3.css
----.gitignore
Github回购协议
repo
----file_1.css
----file_2.css
----file_3.css
----preserve.css
----.gitignore
我的本地目录没有preserve.css
文件。因此,当我提交并推送时,preserve.css
文件在我的repo中被删除。但是,我想在我的repo中保留preserve.css
,即使它不在我的本地目录中
出于个人原因,我希望它只出现在我的github repo中,并且只希望在repo中在线编辑和保存它。但是在本地目录中进行更改和推送会阻止我这样做
我尝试在本地目录中的.gitignore
文件中添加preserve.css
,但没有成功
我如何才能做到这一点?假设本地repo是远程repo的克隆,Git会比较本地和远程repo的内容,以确定做了哪些更改。您可以使用
git status
查看这些更改
为了不“提交”文件的删除,您必须使用git reset HEAD preserve.css取消文件的保存,或者根本不保存文件
1. git add .
2. git reset HEAD preserve.css
3. git commit -m "The message you want"
4. git push remote_name branch
你提交删除了吗?@evolutionxbox我从未删除过
preserve.css
,因为我从未在本地回购中创建过它。关于preserve.css
的所有内容都是在我的github中完成的,您是否进行了这些更改?Git将只删除通过“添加其删除”添加的文件。因此,如果它从未存在于您的本地回购协议中,提交不应将其从github中删除。