HomeToolsAbout

Frequent Actions

Add to Index

# add specific file git add file_name # add all files git add .

Remove from Index

Prefer git rm over other methods

rm removes file or directories from both the staging index and the working directory which is preferred over deleting the file in the file system and having Git detect the deletion

rm will always lead to cleaner diff

git rm deleted_file_name # remove from index only, keep file in filesystem git rm --cached file_name

git restore

# unstage file_name from index git restore --staged file_name # ## Reset the file back to original state after unstaging git restore file_name

Safely reset file to another commit or branch name

git checkout commit_hash -- file_path

git commit

--allow-empty

Creates an empty commit with no changes

  1. when a commit without any change must be pushed to retrigger CI
  2. folding in small code change into previous commit
git commit --allow-empty -m "fix CI"

--no-verify

Can be used to skip pre-hooks

git commit --no-verify

git amend

Use Case

  1. Changing the commit message of the latest commit

Modify the latest commit without creating a new commit

git commit --amend
  1. Modify the latest commit's message with a new commit message
git commit --amend -m "an updated commit message"
AboutContact