-
Git
- Stash
git stashsaves a change before switching to a new branchgit stash popapplies the latest stash and deletes the stash from the stash listgit stash listshows the list of all stashesgit stash apply stash_IDapply the # or stash ID from the stash listgit stash drop stash_IDdeletes the stash with stash_ID from the stash listgit stash cleardeletes all stash - Retrieve Lost Commits
gitk --all $(git fsck --no-reflog | Select-String "(dangling commit )(.*)" | %{ $.Line.Split(' ')[2] })git apply #####OR Search inside the pop up window and simply copy paste the code back Link: https://stackoverflow.com/questions/89332/how-do-i-recover-a-dropped-stash-in-git - Revert Single File From Commit
git checkout [commit ID] -- path/to/fileLink: https://dev.to/lofiandcode/git-and-github-how-to-revert-a-single-file-dha - Revert Multiple File From Commit
git reset --soft HEAD^git restore --staged path/to/unwanted_file#Note: NEVER remove the "--soft" tag, because if you remove it. The reset will be a hard reset and will remove all the changed files from the commit and sometimes it will lead into lost files and you will need to go back to "1. Retrieve Lost Commits". So for a safe practice, just use the soft reset ("--soft") Link: https://stackoverflow.com/questions/12481639/remove-file-from-latest-commit
- Stash
-
Pull-requests
-
Update Pull-requests After pushing your commits to create a new pull request, sometimes you realize you need to change a file that is already committed on the pull request. So you would change the file, git add, commit, push it and then realize you cannot push it. The following command will help you resolve this issue.
git push origin master --force#Note: Use with precaution because we are using the force push. So try to limit the usage of this to directly push codes to the master branch. A great alternative would be using --force-with-lease because it does not overwrite any work on the master branch if more commits are added to the master branch. (In depth comparisons of force vs force-with-lease https://itnext.io/git-force-vs-force-with-lease-9d0e753e8c41)
-