Get Started. It's Free
or sign up with your email address
Git by Mind Map: Git

1. Update commit

1.1. Add some changes to the latest commit (before push)

1.1.1. git commit --amend

1.2. Fix latest commit message (before push)

1.2.1. git commit --amend -m "updated message"

2. Work with single file

2.1. Cancel changes in one file, revert to the latest commit state

2.1.1. git checkout -- <bad filename>

2.2. Restore file as it was at the moment in time

2.2.1. git checkout <SHA> -- <filename>

3. Get information

3.1. Who changed the lines 10-15 in the file

3.1.1. git blame -L 10,15 <filename>

3.2. Commit log

3.2.1. git log

3.3. Detailed user actions

3.3.1. git reflog

3.4. Get changes for single file

3.4.1. git log -p <filename>

3.5. Get changes for merge

3.5.1. git diff <2nd SHA>...<1st SHA>

3.6. Get information about merges only

3.6.1. git log --merges

3.7. Get master branch history

3.7.1. git log --first-parent

3.8. What branch does commit refer to?

3.8.1. git reflog show --all | grep <SHA>

4. Cancel changes

4.1. Cancel changes from last commit (with copy to clipboard)

4.1.1. git stash

5. Cancel commit

5.1. on local, before push

5.2. after push to master (latest)

5.3. after push to master but master was already updated by other commits

5.3.1. git revert <SHA>

6. Merge

6.1. How to cancel merge with conflicts

6.1.1. git merge --abort

6.2. How to merge latest changes from remote master to local branch?

6.2.1. // in your local branch git pull origin master

6.3. What was lost during merge?

6.3.1. git log --merges find R = merge result commit find X = first commit find Y = second commit git diff X R git diff Y R (shows what data from X/Y is missing in result commit)

7. How to properly push changes from custom branch

7.1. git checkout master git pull git checkout custom-branch git merge master <fix conflicts if necessary and commit them> git checkout master git merge custom-branch npm run lint <check if no errors while compiling> git pull git push

8. Tracking files

8.1. How to stop tracking file

8.1.1. git rm --cached <filename>

8.1.2. git rm --cached <filename> -r