Posts

Showing posts with the label Git

Check Change Files in Git

You can compare only the files that differ between your current local branch and another branch on the remote using Git. Here are the most common and useful ways, from simplest to more detailed. 1. List only the changed files (most common) git fetch origin git diff --name-only origin/other-branch If you want to be explicit about your current branch: git diff --name-only origin/other-branch..HEAD ➡️ Shows only file paths that are different. 2. List changed files with change type (added / modified / deleted) git diff --name-status origin/other-branch..HEAD Example output: M src/app.js A src/new-file.ts D src/old-file.css 3. Compare against the common ancestor (recommended for PR-style comparison) This avoids noise from changes made in the target branch after you branched. git diff --name-only origin/other-branch...HEAD ... (three dots) means: changes on your branch since it diverged from the other branch This is usually what you want when prepari...

Compare local files with remote Git repo using WinMerge

Here’s a clean step-by-step way to compare your local WSL repo folder vs the remote repo state in WinMerge , and then show only changed files . 1) In WSL: go to your repo and fetch remote cd /path/to/your/repo git fetch origin 2) In WSL: create a “remote snapshot” folder (safe, no checkout) This exports the remote branch into a temp folder. REMOTE_BRANCH=origin/main SNAP=/tmp/repo_remote_snapshot rm -rf " $SNAP " mkdir -p " $SNAP " git archive " $REMOTE_BRANCH " | tar -x -C " $SNAP " Change origin/main if your remote branch is different (e.g. origin/master , origin/develop ). 3) Open WinMerge and start a folder compare Launch WinMerge (on Windows) File → Open… (or “Open”) Select Folder Compare 4) Pick the two folders (WSL paths via \\wsl$ ) In WinMerge: Left (Local working folder) Use your actual repo path in WSL: \\wsl$\Ubuntu\home\<youruser>\ path \ to \your\repo Right (Remote snapshot folder) \\wsl $ \Ubu...

Revert Git to last commit

  If you want to revert everything back to the last commit and discard all local changes , use this 👇 🔥 Hard reset (most common & safest) This restores your working tree and index to the latest commit . git reset --hard HEAD What this does ❌ Discards all modified files ❌ Discards all staged files ❌ Discards all untracked changes in tracked files ✅ Leaves your repo exactly as the last commit 🧹 Also remove untracked files (optional but often needed) If you also want to delete untracked files and folders : git clean -fd Or preview first (recommended): git clean -fdn ✅ One-liner (full nuclear option) git reset --hard HEAD && git clean -fd ⚠️ Important warning This is irreversible unless: Changes were committed Or stashed Or still exist elsewhere

"Unpushed" from Git remote branch

✅ SAFE (Recommended): Revert the pushed commit Find the commit you pushed git log --oneline Copy the commit hash (e.g. abc1234 ). Revert that commit git revert abc1234 Git creates a new commit that undoes the changes. If multiple commits: git revert abc1234..HEAD Push the revert git push ✅ Best practice for shared branches ⚠️ DANGEROUS (Only if you are 100% sure) Use this only if you are the only one working on the branch or it’s a personal feature branch: Reset and force-push git reset --hard HEAD~1 git push --force This will remove the commit locally and rewrite remote history ❌. If the pushed commit was a deletion and you want to restore a file: git checkout HEAD~1 -- path/to/file git commit -m "Restore accidentally deleted file" git push Which one should YOU use? Situation Command Shared branch git revert <commit> ...

Revert file from Git remote branch

You can revert just that single file from other remote branch without touching anything else. Option 1: Restore file from remote branch (recommended) git fetch origin git checkout origin/[remote_branch] -- file_path_in_GIT This will: Take the version of the file from remote origin/[remote_branch] Overwrite your local copy Leave you on your current branch Then commit it: git commit -m "Revert file from other branch" Option 2: If your local branch is already tracking the remote branch You can shorten it to: git checkout [remote_branch] -- file_path_in_GIT (Still followed by a commit.) Option 3: Using modern git restore (Git ≥ 2.23) git fetch origin git restore --source=origin/[remote_branch] -- file_path_in_GIT Then commit: git commit -m " Revert file from other branch" Verify before committing (optional but smart) git diff ⚠️ Notes This does not switch branches This does not affec...

Remove Git Context Menu

 Delete   Computer\HKEY_CLASSES_ROOT\Directory\Background\shell\git_gui Computer\HKEY_CLASSES_ROOT\Directory\Background\shell\git_shell Computer\HKEY_CLASSES_ROOT\LibraryFolder\background\shell\git_gui Computer\HKEY_CLASSES_ROOT\LibraryFolder\background\shell\git_shell Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\git_gui Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\git_shell   Credit:  https://superuser.com/questions/1347461/remove-item-from-context-menu-of-folder-empty-space https://stackoverflow.com/questions/47084443/how-to-remove-git-from-menu-context-in-documents

Copy local git branch

git branch copyOfMyBranch MyBranch git checkout copyOfMyBranch

Allow multiple git flow hotfix branches to exist at the same time

git flow config multi-hotfix true   or   git config --add gitflow.multi-hotfix true

Delete Git branch

delete branch locally git branch -d localBranchName delete branch remotely git push origin --delete remoteBranchName

How to clone a Git branch

git clone --branch --single-branch [ ]