HOW TO SEE ALL THE COMMITS WITH HASH
git log --oneline -10 git log --oneline --author=rahul

APPLY SPECIFIC COMMITS FROM FROM ONE BRANCH TO OTHER/MASTER
git cherry-pick <commithash> git stash apply stash@{0} // apply changes from a stash git cherry-pick -X theirs 5cf3412 // forcefully override local changes
SHOW ALL THE FILES FROM A COMMIT USING HASH
git show --pretty="" --name-only <commithash>
HOW TO DIFF ON A FILE
git diff HEAD [filename] // compare the working directory with local repository. git diff [filename] // compare the working directory with index. git diff --cached [filename] // compare the index with local repository. git diff c305c36f..79fc2a6f (oldhash..newhash) git diff like "git diff origin/helid-release" // when you are on master branch after doing a merge git diff --staged // git diff on staged files
HOW TO RENAME A BRANCH
git branch -m new_name
REMOVE LOCAL CHANGES WITH LATEST
git reset --hard HEAD // remove all the local changes git reset --hard HEAD~1 // remove all the local changes and last one commit git reset --soft HEAD~2 // uncommit last 2 commits but keep the changes git revert commitID // remove a specific commit = undo changes and add a new commit git checkout -- /path/to/file // remove changes for a particuluar file
HOW TO DELETE A LOCAL BRANCH
git branch -d bug-23244 // only allow if branch is merged and pushed git branch -D bug-2324234 // forcefully deletes the branch.
HOW TO UNSTAGE A FILE
git reset -- <filePath> // It will unstage any staged changes for the given file(s).
SEE LIST OF FILES BEFORE GIT PUSH
git diff --stat --cached origin/release2022
CHANGE LAST COMMIT MESSAGE
git commit --amend
CHANGE LAST NTH COMMIT MESSAGE
git rebase -i HEAD~4 It will show you last 4 commits press insert and then change "pick" to "reword" for that 4th commit press esc write ":wq" to write and quit now it will show you commit message to change it make the change and write it. git log --oneline -4 // to see your commit message is changed.
HOW TO MERGE LAST 3 COMMITS into first commit
git rebase -i HEAD~3 press insert > change the "pick" for 2nd and 3rd commit to "f" press escape > type :wq to write(save) and quit(exit) git log --oneline -5 // now there should be one commit instead of 3
ADD ONLY TRACED FILES
git add -u
APPLY ONLY PARTICULAR FILES FROM A STASH
git checkout stash@{0} -- path/to/file
How to remove local untracked files from the current Git branch
git clean -n //see the files git clean -f // actually remove the files
HOW TO SWITCH BETWEEN BRANCHES WITH LOCAL CHANGES
git stash // save local changes to stash git checkout new_branch_name // move to new branch git stash pop // reapply local changes from stash and delete the stash