What are the steps to unstage files and discard changes in the working directory

0 votes
I want to undo certain changes made to the working directory in my Git repository. How do I do it?
Nov 26, 2019 in DevOps Tools by anonymous
• 19,610 points
1,675 views

1 answer to this question.

0 votes

If the git status command displays 'myfile.txt' as file pending to commit then

  • To unstage a file(which is not yet committed but in staging stage); command 'git reset <file-name>'  is used. After using 'git reset HEAD myfile.txt' command; 'git status' command won't show myfile.txt within the list of files unfinished to commit, currently it'll be displayed below the list of the unstage/untracked files.

  • Now to discard the changes('myfile.txt') in working directory; command 'git checkout -- <file-name>' is used. After using 'git checkout -- myfile.txt' command; 'git status' command will not show myfile.txt in the list of unstage/untracked files as this file 'myfile.txt' will be replaced with the last committed version from the repository.

answered Nov 26, 2019 by Sirajul
• 59,230 points

Related Questions In DevOps Tools

0 votes
1 answer
0 votes
0 answers

How do you restructure working directory files in a git repository?

How do you restructure working directory files ...READ MORE

Nov 26, 2019 in DevOps Tools by anonymous
• 19,610 points
465 views
0 votes
3 answers
0 votes
1 answer

Want a command to be executed in Salt only if a directory is empty

You should consider using this inside your ...READ MORE

answered Jun 12, 2018 in DevOps Tools by Damon Salvatore
• 5,980 points
1,461 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,459 views
+2 votes
1 answer
0 votes
1 answer

What are the steps to permanently remove a committed file from the repository?

To remove a file for example 'myfile.txt'; ...READ MORE

answered Nov 26, 2019 in DevOps Tools by Sirajul
• 59,230 points
1,384 views
0 votes
1 answer

How do you restructure working directory files in a git repository?

If we have a file called 'myfile.txt' ...READ MORE

answered Nov 26, 2019 in DevOps Tools by anonymous
• 59,230 points
2,839 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP