Git Cheat sheet

You are here:
Estimated reading time: 1 min

Add Files Changes

git commit add path/to/file.ext;
git commit add path/to/file2.ext;
git commit -m "Added some changes"

Error: Your local changes to the following files would be overwritten by merge

Discard changes to conflic files with:

git checkout -- path/to/file-a.ext;
git checkout -- path/to/file-b.ext;
git checkout -- path/to/file-c.ext;

Files inside folders

git checkout -- path/to;

Go to particular revision

Use git checkout <sha1> to check out a particular commit.

Where <sha1> is the commit unique number that you can obtain with git log

Here are some options after you are in detached head status:

  • Copy the files or make the changes that you need to a folder outside your git folder, checkout the branch were you need them git checkout <existingBranch> and replace files
  • Create a new local branch git checkout -b <new_branch_name> <sha1>

Source

Revert back to certain commit

git reset --hard 4a155e5

Source

How To Write Proper Git Commit Messages

Write “-“.Press Esc and then type :wq to save and exit.

Source

Revert to specific commit

Set git user

git config user.name "Adalberto Vargas" git config user.email adalberto.vargas@abraham

Remove File from Pull Request

git checkout HEAD^ -- path/to/file;
rm path/to/file;
git add path/to/file;
git commit -m "Reverted changes on this file";
git checkout HEAD^ -- /path/to/file;
Was this article helpful?
Dislike 0
Views: 82