删除github某一个仓库中的一个文件夹或一个文件

本文介绍了如何通过Git命令行删除GitHub仓库中的特定文件。首先,进入本地仓库目录,使用`git pull`同步远程仓库。然后,使用`git rm`命令删除指定文件,并通过`git commit`提交变更,最后使用`git push`将更新推送到GitHub。如果遇到网络问题,可能需要重试`git push`操作。
摘要由CSDN通过智能技术生成

问题描述:
提交文件个时候,将一个未命名3.c文件提交了,我想将其删掉,可是github只能删除仓库,不能删除某一个仓库的文件夹或某一个文件

问题解决:
1.
首先进入你的master(或我的是main)文件夹下(也就是所要删除的文件夹所在的那个仓库), Git Bash Here ,打开命令窗口
2.
git pull origin main:将远程仓库里面的项目拉取下来
3.
dir:查看里面有什么文件或文件夹
4.
git rm -r --cached 未命名3.c:删除所要删除的文件
5.
git commit -m ‘删除了未命名的文件’:添加删除文件夹的说明
6.
git push -u origin main:将本次更改更新到github上去(我第一次为什么失败,我猜想是用google浏览器访问,由于访问github网站不稳定造成的,所以第2次才功)

许荣@DESKTOP-A30VNHE MINGW64 /d/c/gitSource/c- (main)
$ git --help
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           [--super-prefix=<path>] [--config-env=<name>=<envvar>]
           <command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
   clone             Clone a repository into a new directory
   init              Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
   add               Add file contents to the index
   mv                Move or rename a file, a directory, or a symlink
   restore           Restore working tree files
   rm                Remove files from the working tree and from the index
   sparse-checkout   Initialize and modify the sparse-checkout

examine the history and state (see also: git help revisions)
   bisect            Use binary search to find the commit that introduced a bug
   diff              Show changes between commits, commit and working tree, etc
   grep              Print lines matching a pattern
   log               Show commit logs
   show              Show various types of objects
   status            Show the working tree status

grow, mark and tweak your common history
   branch            List, create, or delete branches
   commit            Record changes to the repository
   merge             Join two or more development histories together
   rebase            Reapply commits on top of another base tip
   reset             Reset current HEAD to the specified state
   switch            Switch branches
   tag               Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
   fetch             Download objects and refs from another repository
   pull              Fetch from and integrate with another repository or a local branch
   push              Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.

许荣@DESKTOP-A30VNHE MINGW64 /d/c/gitSource/c- (main)
$ git pull origin main
From https://github.com
 * branch            main       -> FETCH_HEAD
Already up to date.

许荣@DESKTOP-A30VNHE MINGW64 /d/c/gitSource/c- (main)
$ dir
README.md  sourse

许荣@DESKTOP-A30VNHE MINGW64 /d/c/gitSource/c- (main)
$ cd sourse

许荣@DESKTOP-A30VNHE MINGW64 /d/c/gitSource/c-/sourse (main)
$ dir
BATMaxConsequnceSum.c  BATMaxConsequnceSum.exe  Queue.c  struct.c  未命名3.c

许荣@DESKTOP-A30VNHE MINGW64 /d/c/gitSource/c-/sourse (main)
$ git rm -r --cached 未命名3.c
rm 'sourse/未命名3.c'

许荣@DESKTOP-A30VNHE MINGW64 /d/c/gitSource/c-/sourse (main)
$ git commit -m '删除了未命名的文件'
[main 62882f9] 删除了未命名的文件
 1 file changed, 18 deletions(-)
 delete mode 100644 "sourse/\346\234\252\345\221\275\345\220\2153.c"

许荣@DESKTOP-A30VNHE MINGW64 /d/c/gitSource/c-/sourse (main)
$ git push -u origin main
fatal: unable to access 'https://github.com': OpenSSL SSL_read: Connection was reset, errno 10054

许荣@DESKTOP-A30VNHE MINGW64 /d/c/gitSource/c-/sourse (main)
$ git push -u origin main
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 335 bytes | 335.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com
   de36321..62882f9  main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.

许荣@DESKTOP-A30VNHE MINGW64 /d/c/gitSource/c-/sourse (main)
$
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值