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,996 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

What are the main weaknesses of Bitbucket Cloud compared to GitHub in your opinion?

What do you see as the weaknesses ...READ MORE

Oct 14 in DevOps Tools by anonymous
• 3,070 points

edited Oct 22 by anonymous 69 views
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
626 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
4,024 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,812 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
3,405 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