see all folders including those starting with . (e.g: .git folder)
Command
Description
git commit -am "message"
add and commit
git commit --amend -m <message>
fix the last commit
git ls-files
list of tracked files
Note:git commit --amend will update and replace the most recent commit with a new commit that combines any staged changes with the contents of the previous commit. With nothing currently staged, this just rewrites the previous commit message.
Note: All comparisons are done for files tracked by git. If file is not in the list of git tracked files (git ls-files), the changes will not be shown.
To do this by pasting some line in the .gitconfig with VS Code.
Run git config --global core.editor "code --wait" from the command line.
From here you can enter the command git config --global -e. You will want to paste in the code in the "Extra Block" below.
[user]
name = EricDJohnson
email = [email protected]
# Comment: You just added this via 'git config --global core.editor "code --wait"'
[code]
editor = code --wait
# Comment: Start of "Extra Block"
# Comment: This is to unlock VSCode as your git diff and git merge tool
[merge]
tool = vscode
[mergetool "vscode"]
cmd = code --wait $MERGED
[diff]
tool = vscode
[difftool "vscode"]
cmd = code --wait --diff $LOCAL $REMOTE
# Comment: End of "Extra Block"
Now in your git directory with a conflict, run git mergetool and you have VSCode helping you handle the merge conflict! To compare, run git difftool.
Turning of the Default Prompt
Command
Description
git config --global diftool.prompt false
By this setting, we will not have to deal with the prompt anymore.
git config --global mergetool.prompt false
git config --global diftool.prompt false
git will not keep .orig files after merge
Note: After performing a merge, the original file with conflict markers can be saved as a file with a .orig extension.If this variable is set to false then this file is not preserved. Defaults to true (i.e. keep the backup files).
Note: git reflog is different with git log as it includes everything we have done. For example. git log does not show moving HEAD between different commits.
Cherry-Pick
Command
Description
git cherry-pick <commit_id>
cherry-pick a specific commit (<commit_id>)
Rewriting History
Update Last Commit
git ammend is the command to rewrite the history by changing the last commit or on your own branch at the public that no one has branched off of or is relying on the history of your branch.
Because once you change that commit history, you are going to create a huge conflict with anybody who is relying on that history.
You definitely never want to do this on master.
Note: Be careful of using git ammend. You only want to do this on a local branch
Command
Description
git commit --amend -m <message>
updates the last commit
Checkout to Orphaned Commit after ammend
First get the commit id from git reflog.
Checkout to the commit by git checkout <commit_id>.