Git: Revert file after conflict

 Git: Revert file after conflict

Suppose your file got conflicted after taking pull and want to revert changes then use below command.


git checkout HEAD my/filename.js

Reference: 
https://stackoverflow.com/questions/22565184/git-how-to-revert-after-a-merge-conflict-corruption

Switch node versions using nvm

 Switch NodeJs versions using nvm


List all nodejs versions available

nvm ls-remote


Install specific version

nvm install 14.18.1


Install latest nodejs

nvm install node


List nodejs versions available in the machine

nvm ls


Switch to nodejs version

nvm use 16.13.0


Uninstall nodejs version

nvm uninstall 16.13.0

Git: Get changes from another branch

 Git: Get changes from another branch 


Suppose you are working branchA and somebody merged changes to main branch. You want pull latest changes from main to branchA.

option 1

git checkout main

git pull

git checkout branchA

git merge main


option 2

git rebase main


option 3

git pull origin main



Git: Save user credentials

 Git: Save Username and Password


To avoid prompting username and password, run below command

git config --global credential.helper store

then

git pull


Reference: https://stackoverflow.com/questions/35942754/how-can-i-save-username-and-password-in-git 

React: File download

 React: File download


Got a requirement to save api response data (blob) to a file.


setLoading(true);
const responseData = await callApi();
setLoading(false);
var blob = new Blob([responseData], { type: "application/json" });
let url = window.URL.createObjectURL(blob);

// Creating the hyperlink and auto click it to start the download
let link = document.createElement("a");
link.href = url;
link.download = "samplefile.json";
link.click();

GIT: Edit last commit message

 GIT: Edit last commit message (not pushed)


git commit --amend -m "New commit message"

Reference
https://stackoverflow.com/questions/179123/how-to-modify-existing-unpushed-commit-messages