Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
git_add_rm [2019/02/28 15:11] rpjdaygit_add_rm [2019/03/18 12:29] (current) – [-u, --update option] rpjday
Line 121: Line 121:
 <code> <code>
 $ git rm README.asc $ git rm README.asc
-$ git rm -r theme+$ git rm -r theme/
 </code> </code>
  
Line 152: Line 152:
 ==== "-u", "--update" option ==== ==== "-u", "--update" option ====
  
-Stage all changes and deletions of existing files, but not addition of new files:+Stage all changes and deletions of existing files, //but not addition of new files//:
  
 <code> <code>
Line 249: Line 249:
     README.asc     README.asc
 (use --cached to keep the file, or -f to force removal) (use --cached to keep the file, or -f to force removal)
 +$
 +</code>
 +
 +==== "git rm" and empty directories ====
 +
 +Since Git cannot version empty directories, any ''git rm'' command that results in any empty directories will result in the removal of //all// resulting empty directories.
 +
 +===== Accessing deleted files =====
 +
 +==== Listing all deleted files throughout history ====
 +
 +<code>
 +$ git log --diff-filter=D --summary
 +commit 97b26b7710aed5d41a6a079fbc7279e4bc31e1f5
 +Author: Adrien Ollier <aollier@users.noreply.github.com>
 +Date:   Mon Nov 12 12:40:05 2018 +0100
 +
 +    removed unused images
 +
 + delete mode 100644 images/emoji.png
 + delete mode 100644 images/notifications.png
 +
 +commit 99c2df95f5839f6c6df75eedbfc06cac35389d91
 +Author: Adrien Ollier <aollier@users.noreply.github.com>
 +Date:   Thu Jun 15 12:52:03 2017 +0200
 +
 +    removed unused images
 +
 + delete mode 100644 book/04-git-server/images/gitlab-broadcast.png
 + delete mode 100644 book/05-distributed-git/images/merging-workflows-4 2.png
 + delete mode 100644 book/06-github/images/blink-pull-request-open copy.png
 + delete mode 100644 book/06-github/images/blink-pull-request-open.png
 + delete mode 100644 book/06-github/images/hubot.png
 +... snip ...
 +</code>
 +
 +==== Recovering a deleted file ====
 +
 +Display the most recent commit that references the file:
 +
 +<code>
 +$ git log -1 -- OUTLINE.txt
 +commit b86814bf758645cf1d0ea8a6cbfd1486d257f4dc
 +Author: Scott Chacon <schacon@gmail.com>
 +Date:   Tue Oct 14 10:55:34 2014 +0200
 +
 +    remove changes notes and initial outline
 +$
 +</code>
 +
 +Now display its content from the //previous// commit (optionally redirect to file):
 +
 +<code>
 +$ git show b86814bf758645cf1d0ea8a6cbfd1486d257f4dc^:OUTLINE.txt
 +1. Getting Started
 +1.1 About Version Control
 +    * Local Version Control Systems
 +    * Centralized Version Control Systems
 +    * Distributed Version Control Systems
 +... snip ...
 +</code>
 +
 +You can also:
 +
 +<code>
 +$ git rev-list -n 1 HEAD -- OUTLINE.txt
 +b86814bf758645cf1d0ea8a6cbfd1486d257f4dc
 $ $
 </code> </code>
  • git_add_rm.1551366716.txt.gz
  • Last modified: 2019/02/28 15:11
  • by rpjday