Menghapus File Pada Repository Github Dengan Terminal Pada Mac

 

Untuk menghapus file/folder pada git repository dapat menggunakan perintah git rm.

$ git rm filename

Tetapi jika anda hanya ingin menghapus file pada repository dan tidak menghapusnya pada file anda, tambahkan flag --cache

$ git rm --cache filename

Contoh:


sh-3.2# cd /Applications/xampp/htdocs/tka-jakon/application/controllers


sh-3.2# ls

    .DS_Store Menus.php User.php penetapan

    Auth.php Sekretariat.php audit registrasi

    Home.php Unit.php index.html verifikasi


sh-3.2# git rm Sekretariat.php


sh-3.2# git status

    On branch main

    Your branch is up to date with 'origin/main'.


    Changes to be committed:

    (use "git reset HEAD <file>..." to unstage)


deleted:    Sekretariat.php


sh-3.2# git reset Sekretariat.php

    fatal: ambiguous argument 'Sekretariat.php': unknown revision or path not in the working tree.

    Use '--' to separate paths from revisions, like this:

    'git <command> [<revision>...] -- [<file>...]'


sh-3.2# git commit -a -m "menghapus file tidak diperlukan"

    [main a59b682] menghapus file tidak diperlukan

     1 file changed, 113 deletions(-)

     delete mode 100644 application/controllers/Sekretariat.php


sh-3.2# git push

    Enumerating objects: 7, done.

    Counting objects: 100% (7/7), done.

    Delta compression using up to 4 threads

    Compressing objects: 100% (4/4), done.

    Writing objects: 100% (4/4), 360 bytes | 360.00 KiB/s, done.

    Total 4 (delta 3), reused 0 (delta 0)

    remote: Resolving deltas: 100% (3/3), completed with 3 local objects.

    To github.com:LPJKN/tka-jakon.git

    7bea4cd..a59b682  main -> main



Kemudian commit dan push ke repository anda.

Note:
Untuk menghapus folder yang berisi banyak file, tambahkan flag -r

$ git rm --cache folder/ -r


Oleh: Samso Supriyatna S.Kom

Referensi:
– 
https://blog.boniw.io/cara-menghapus-file-pada-git-repository/

Git Docs


Komentar

Postingan populer dari blog ini

UAS Audit Teknologi Informasi Menggunakan ACL

Web Service

Cara menjalankan kode Python dari dalam Visual Studio Code