1

I am new to git. I don't actually use it for any project but just as a storage for all my dotfiles.

I did a git commit and just after that, I realised that was just unnecessary because it was an incomplete change. So, instead of doing another edit, commit and push, I reset the last good commit using git reset --hard #commit_shaN and pushed it to remote with help from here : Git reset --hard and a remote repository. Remote is fine now but locally when I make new changes and try to do new commits, it says :

    On branch master
    Your branch is up to date with 'origin/master'.

    Untracked files:
         blah
         blah
         blah
         blah
         blah
         blah
    nothing added to commit but untracked files present

I searched the web for help and got this : Git:nothing added to commit but untracked files present. As this page says, I added those untracked files to .gitignore with no result. It still gives the same output. Thanks in advance for your help.

  • Are you certain that you actually modified any tracked files? Note that you didn't necessarily have to do a hard reset if you wanted to keep those partial changes. – Tim Biegeleisen Feb 13 '19 at 05:30
  • Yeah, I modified them and no, I don't want to keep any changes that I made after that "good" commit. –  Feb 13 '19 at 05:32
  • 1
    Well according to Git you did not modify any tracked files. – Tim Biegeleisen Feb 13 '19 at 05:36

1 Answers1

0
git reset --hard HEAD~1/ git reset --hard #commit_shaN

remove your last commit and also remove change of last commit.

If you want to undo last commit or unstage last commit use soft instead of hard

git reset --soft HEAD~1/ git reset --soft #commit_shaN

Then add new changes and them rename commit(new commit) or commit again

Untracked files: You can remove the untracked file using these two commands

git clean -n
git clean -f

Untracked folders: You can remove the untracked folder using deleted them it's the only way to remove untracked folders.

rm -rf pathOfFFolder

write this command with sudo or run terminal/cmd as administration if permission issue is occured

Ashok
  • 2,846
  • 1
  • 12
  • 20