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
2,018 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
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
• 5,040 points

edited Oct 22 by anonymous 91 views
0 votes
1 answer

What are some strategies for managing large volumes of build artifacts in Jenkins? Can you share tips or scripts for archiving and cleaning up old artifacts to save space?

In Jenkins, large volumes of artifacts from builds are the heart and soul of optimizing storage usage ...READ MORE

answered Nov 14 in DevOps Tools by Gagana
• 6,530 points
68 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,065 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,834 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,466 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