Thursday, May 13, 2021

GIT Basics - 4 Backing out files

 This is about removing files from staging area and Working directory.

To  remove from stage

git reset  HEAD {name of the file}

To remove from Working directory

git checkout -- {filename}

let's go though below steps

git status - to make sure clean repo

create a file or get a file from repo - local repo

cat lv1-file.txt

add some lines and save

git status

you will see Changes not staged for commit. modified: lv1-file.txt

git add lv1-file.txt

git status

you will see Changes to be committed. modified. modified: lv1-file.txt

Note: File is in staged area

In git status message it shows what to do .git reset  HEAD {name of the file}

git reset HEAD lv1-file.txt

git status
Changes not staged for commit. modified: lv1-file.txt

Note: File is unstaged. In other words in Working directory

Now if you do not need any of the changes. 

If you run git status will tell what to do. git checkout -- {filename}

git checkout -- lv1-file.txt

Now if you check status, it will be clean

git status

nothing to commit, working directory clean.



No comments:

Post a Comment