How to undo the latest git commit

We wrote some time ago about how to undo the latest changes without using git stash

But today I will give a quick line to “cancel” the latest commit that you did:

git reset --soft HEAD^

This will keep the changes you did.

Thanks to Andrew:

Uncommited files in git repo: how to reject local changes

It has happened to me a few times: I do local changes and test stuff locally. Then I come back a while later (weeks) and I have forgotten what were the changes for. In order to play it safe, I want to reset my local files to what is there on the github repo, so here is the solution

git fetch --all
git reset --hard origin/master

 Thanks RNA!

DropBox and GitHub: fatal: Reference has invalid format: ‘refs/heads/master

I am keeping all my code in a DropBox synchronized folder.

Besides, I keep the code in GitHub.

Well, this seems a bit redundant, but I prefer to do so because coding is an important part of my business.

But recently I experienced a problem and I want to share it with you.

I had to reformat my hard drive because of file corruption problems that could not be solved otherwise. But before I reformatted I was able to copy the files to an external hard drive. This was in a Mac OS X 10.7 Mountain Lion environment running on MacBook Pro 13”. I had to use Recovery Mode to do so.

Because I had 50+ Gbytes in DropBox, I decided to copy the info from the back-up drive to the new drive, so I did not have to wait ages to get the 700k+ files in my DropBox. And everything was fine until I realised that the local version was more recent than the DropBox one. This happened because at the time of losing my hard drive, the files in DropBox were not fully synchronised, so the local version was more recent. What I would not expect from DropBox is that it considers the on-line version to be the correct one even if the local is more recent. It should ask at least! 

How did I notice the problem? 4 days after the crash, the files finally downloaded from DropBox and replaced the local versions without asking. I think that DropBox should have a professional mode, more similar to git, where you can decide what you do in case of conflict.

So I was not able to do git pull in my code because the local HEAD did not mach the github HEAD. I was getting this error 

fatal: Reference has invalid format: ‘refs/heads/master 

Solution: I renamed the folder and created a new one from the backup hard drive. Now it seems to survive to DropBox synchronization!

GIT and GitHub: how to avoid entering credentials every time

Do you have some repos and have to enter the credentials everytime you connect to github? the solution is given here:

It is caused because you referred to the https instead of the git address. So you will have to do the following:

git remote set-url origin