Git- undo working directory and amend commits

Undo working directory

If you want to undo any changes to working directory, user following command-

git checkout -- file.txt

Use — to undo a file in a current branch.

You may checkout specific commit or old version, use following command.

To see the commit user-

git log

Copy the first 10 characters of SHA and use following command to checkout a specific commit-

git checkout sha121212 -- file.txt

Where sha121212 is a SHA of the specific commit.

Amend commits

If you want to amend the commit i.e. something in the repository, you may do that using amend command. Note only the last/recent commit i.e. the HEAD point to can be amended and in this case date and SHA will be changes along with message, use following command-

git commit --amend -m "message goes here"

You may check the commit changes in log-

 git log

If you want to revert the current commit use following command-

git revert SHA21121

SHA21121 is the SHA for that commit.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s