How to delete a file in git at different stages in the commit process

What is the proper way to delete a file from Git in these cases?

Case 1: I created a new file, but I haven't done git add new_file.html Solution: I can just delete new_file.html from my computer.

Case 2: I created a new file, I have done git add new_file.html, but I have not committed these changes. Solution: ?

Case 3: I created a new file, I have done git add new_file.html, I have done git commit -m 'added a new file here!'. Solution: ?

Case 4: I created a new file, I have done git add new_file.html, I have done git commit -m 'added a new file here!', and I have merged this branch with master branch. Solution: ?

Answers


For case 2

git reset HEAD new_file.html && rm new_file.html

For case 3

git reset --hard HEAD~

For case 4, just revert the commit

git revert HEAD # git revert <commit-id>

Need Your Help


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.