本文介绍了如何在git中使用gitignore命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是第一次使用git.我将我的分支推送到github上,并将所有库和文档推送到github中.现在我该怎么办,我该如何使用gitignore命令再次避免相同的错误.
I'm working first time on git. I have pushed my branch on github and it pushed all the library and documents into the github. Now what can I do and how can I use gitignore command to avoid the same mistake again.
推荐答案
因此,根据您所说的,这些文件是您不想删除但也不希望推送到github
的库/文档.假设您的项目位于文件夹your_project
和一个doc目录:your_project/doc
.
So based on what you said, these files are libraries/documentation you don't want to delete but also don't want to push to github
. Let say you have your project in folder your_project
and a doc directory: your_project/doc
.
- 从项目目录中删除它(实际上并没有删除它):
git rm --cached doc/*
- 如果您还没有
.gitignore
,则可以在项目文件夹中创建一个:project/.gitignore
. - 将
doc/*
放入.gitignore - 暂存要提交的文件:
git add project/.gitignore
- 提交:
git commit -m "message"
. - 将更改推送到
github
.
- Remove it from the project directory (without actually deleting it):
git rm --cached doc/*
- If you don't already have a
.gitignore
, you can make one right inside of your project folder:project/.gitignore
. - Put
doc/*
in the .gitignore - Stage the file to commit:
git add project/.gitignore
- Commit:
git commit -m "message"
. - Push your change to
github
.
这篇关于如何在git中使用gitignore命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!