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 in DevOps Tools by anonymous
• 6,650 points
14 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 by Sirajul
• 40,980 points

Related Questions In DevOps Tools

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 in DevOps Tools by anonymous
• 6,650 points
12 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,510 points
48 views
0 votes
1 answer

how to fix the build with maven in bluemix

As per Bluemix Status Page today DevOps Delivery Pipeline ...READ MORE

answered Jul 6, 2018 in DevOps Tools by Kalgi
• 45,780 points
111 views
+13 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
245 views
0 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 in DevOps Tools by Sirajul
• 40,980 points
10 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 in DevOps Tools by anonymous
• 40,980 points
51 views