首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修改git提交和删除一些额外的文件?

问如何修改git提交和删除一些额外的文件?
EN

Stack Overflow用户
提问于 2016-11-12 07:08:14
回答 3查看 896关注 0票数 0

我对git还比较陌生,只是提交了一些额外的文件,还添加了一些会导致文件错误的内容。

我想删除额外的文件以及推送编辑的文件。我该怎么做?

一个投稿人让我用武力

EN

回答 3

Stack Overflow用户

发布于 2016-11-12 07:17:52

步骤1:

从磁盘中删除不需要的文件。通过修复您需要修复的内容来编辑文件。

步骤2:

执行以下命令:

代码语言:javascript
复制
git add * 
git commit -m "some message"
git push origin master

如果您正在其他分支工作,只需更改您的分支的名称主人。

票数 1
EN

Stack Overflow用户

发布于 2016-11-12 07:10:59

很简单。

通过编辑和添加新内容,按照您希望的方式更改文件系统。

一旦内容准备就绪,将其添加到阶段并提交。

简写版:

代码语言:javascript
复制
// If you only wish to remove files from the repository
git rm --cached <file to remove>

// or if you only wish to remove files form disk & repo
git rm <file to remove>

详细版本:

代码语言:javascript
复制
.. Current commited content 
.. edit any file or remove any file

// Add the changes to the stage area. 
// Any new change here will be added to the latest commit later on
// with the commit --amend flag
git add <files to be changed>

// if you wish to remove the extra files - remove them from stage
// and commit the change
git rm --cached <file to remove>

// Update the latest commit and add the new changes made to the index
git commit --ammend

// Update remote server with the new changes
git push -f origin <branch>
票数 0
EN

Stack Overflow用户

发布于 2016-11-12 08:51:40

要从工作目录和工作树中删除不需要的文件:

代码语言:javascript
复制
git rm <file1> <file2>...
git add . && git commit --amend --no-edit

--amend选项修改HEAD指向的提交,而不是创建新的提交,而--no-edit选项允许您修改提交而不更改提交消息。

若要删除目录,请使用递归选项-r,并随后列出要删除的目录名。您可能希望将其与--dry-run选项(速记:-n)一起使用,以查看哪些文件将被删除。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40560469

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档