Git: go back to a specific commit and discard all commits after it permanently


To permanently go back to a specific commit and discard all commits after it, you can use the following Git commands:

1) Reset to the specific commit:

git reset --hard <commit-hash>

Replace <commit-hash> with the hash of the specific commit you want to reset to. This will move your branch pointer back to that commit and discard any changes in the working directory and staging area.

2) Force push the reset (if working with a remote branch):

If you’re working on a branch that is shared with others or is pushed to a remote repository (e.g., origin), you’ll need to force push the changes to discard the later commits on the remote as well:

git push origin <branch-name> --force

Replace <branch-name> with the name of your branch.

Caution

This is a destructive operation: All the commits after the specified one will be lost permanently unless they exist in another branch or are otherwise referenced.

Make sure you’re certain before running these commands, especially when using --force, as it changes the history on the remote repository, which can affect other collaborators.

Git Cherry Pick Tutorial

#create a release branch from master
git checkout -b release/1.0.5 master


# get the logs for the source branch we want to cherry pick from
git log develop --oneline


# this is the merge commit for DATA-506
951c3f9 (HEAD -> develop, origin/develop, origin/HEAD) Merge pull request #128 from artnetworldwide/feature/DATA-506


# checkout the destination branch (release/1.0.5), in case we switched branches
git checkout release/1.0.5

# cherry pick
# apply the changes introduced by the commit to the current branch (release/1.0.5)
# it creates a new commit
git cherry-pick 951c3f9


# cherry pick for multiple commits
git cherry-pick HASH1 HASH2 HASH2

How to reset, revert, and return to previous states in Git

https://opensource.com/article/18/6/git-reset-revert-rebase-commands

How to use VS Code as your Git editor, difftool, and mergetool

https://www.roboleary.net/vscode/2020/09/15/vscode-git.html

Git –assume-unchanged

To ignore watching/tracking a particular directory/file:

git update-index --assume-unchanged <file>


To undo it and start watching the file again:

git update-index --no-assume-unchanged <file>

Git: Push to / Pull from Both Github and Bitbucket

https://blog.kevinlee.io/blog/2013/03/11/git-push-to-pull-from-both-github-and-bitbucket/

Send A Patch To Someone Using `git format-patch`

https://thoughtbot.com/blog/send-a-patch-to-someone-using-git-format-patch