Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a file from a Gist?

Tags:

github

gist

I accidentally added file to one of my Gists, but I don't know how to delete it. How to do it? (That is, how to delete a file from a Gist, without deleting the whole Gist?)

When I edit and click on (x) on the left of the filename, then both filename and its content disappear, but not the editor. And when I want to save it (Update Gist), there is an error "Files can't be empty".

like image 397
Piotr Migdal Avatar asked Apr 27 '13 13:04

Piotr Migdal


People also ask

How do I delete gist?

Drag the Delete Gist action under Github to the canvas, place the pointer on the action, and then click or double-click the action. The Delete Gist window opens. 2. Edit the Label, if needed.

Can you edit a gist?

How Do I Edit or Delete a Gist? In the top right corner of your gist page, there will be a menu that allows for multiple functions to be performed on your gist. We can edit, delete, unsubscribe, star, embed, copy, share, and download a raw copy or zipped copy of a gist.

How do I permanently delete a file in Git?

Delete Files using git rm. The easiest way to delete a file in your Git repository is to execute the “git rm” command and to specify the file to be deleted. Note that by using the “git rm” command, the file will also be deleted from the filesystem.

What are gist files?

Gists let you share code snippets, entire files, or even applications. You can also use gists to save and share console output when running, debugging, or testing your code. Each gist is a repository that can be cloned or forked by other people.


3 Answers

This worked for me in the UI:

  • update gist
  • delete the contents
  • delete the file's name
  • click on the blue cross where the file name was

The form for the file should disappear.

After that, save your gist.

like image 82
Sebastian N. Avatar answered Sep 23 '22 11:09

Sebastian N.


I didn't find a way through the GUI.

However, remember you can clone a gist, remove the file, and push a new version of that Gist back to GitHub, with that file removed.

P:\git\test>git clone https://gist.github.com/efd7e7774d9526484456.git
Cloning into 'efd7e7774d9526484456'...
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 8 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (8/8), done.

P:\git\test>cd efd7e7774d9526484456

P:\git\test\efd7e7774d9526484456>dir
 Volume in drive P has no label.
 Volume Serial Number is D866-48E1

 Directory of P:\git\test\efd7e7774d9526484456

27/04/2013  16:52    <DIR>          .
27/04/2013  16:52    <DIR>          ..
27/04/2013  16:52                 5 f1
27/04/2013  16:52                 5 f2
               2 File(s)             10 bytes
               2 Dir(s)  43 554 910 208 bytes free

P:\git\test\efd7e7774d9526484456>git rm f2
rm 'f2'

P:\git\test\efd7e7774d9526484456>dir
 Volume in drive P has no label.
 Volume Serial Number is D866-48E1

 Directory of P:\git\days\efd7e7774d9526484456

27/04/2013  16:52    <DIR>          .
27/04/2013  16:52    <DIR>          ..
27/04/2013  16:52                 5 f1
               1 File(s)              5 bytes
               2 Dir(s)  43 555 000 320 bytes free

P:\git\test\efd7e7774d9526484456>git st
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       deleted:    f2
#

P:\git\test\efd7e7774d9526484456>git commit -m "remove f2"
[master d5a76f4] remove f2
 1 file changed, 1 deletion(-)
 delete mode 100644 f2

P:\git\test\efd7e7774d9526484456>git push

Username for 'https://gist.github.com': VonC
Password for 'https://[email protected]':
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1/1), done.
Writing objects: 100% (2/2), 218 bytes, done.
Total 2 (delta 0), reused 0 (delta 0)
To https://gist.github.com/efd7e7774d9526484456.git
   b93ce40..d5a76f4  master -> master

If you don't want that file in the history (log) of your gist, you can reset --hard:

P:\git\test\days\efd7e7774d9526484456>git lg
* d5a76f4 - (HEAD, origin/master, origin/HEAD, master) remove f2 (3 minutes ago) <VonC>
* b93ce40 -  (7 minutes ago) <VonC>
* d7d8b19 -  (8 minutes ago) <VonC>
* 5eae4d3 -  (8 minutes ago) <VonC>

P:\git\test\efd7e7774d9526484456>git reset --hard d7d8b19
HEAD is now at d7d8b19

P:\git\test\efd7e7774d9526484456>dir
 Volume in drive P has no label.
 Volume Serial Number is D866-48E1

 Directory of P:\git\test\days\efd7e7774d9526484456

27/04/2013  16:52    <DIR>          .
27/04/2013  16:52    <DIR>          ..
27/04/2013  16:52                 5 f1
               1 File(s)              5 bytes
               2 Dir(s)  43 554 832 384 bytes free

P:\git\test\efd7e7774d9526484456>git push --force

Username for 'https://gist.github.com': VonC
Password for 'https://[email protected]':
Total 0 (delta 0), reused 0 (delta 0)
To https://gist.github.com/efd7e7774d9526484456.git
 + d5a76f4...d7d8b19 master -> master (forced update)
like image 43
VonC Avatar answered Sep 22 '22 11:09

VonC


Gists are git repositories, therefore you can clone that gist to your computer, prune that file and force push the gist repo back to GitHub.

You find your clone URL on the left of your gist.

git clone https://gist.github.com/1234567.git
cd 1234567
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch wrong_file' --prune-empty --tag-name-filter cat -- --all
git push origin master --force

This way everything including your history is cleaned up (in this example the file is calles wrong_file).

like image 39
three Avatar answered Sep 21 '22 11:09

three