Skip to content

Instantly share code, notes, and snippets.

@petevb
Last active July 3, 2019 08:04
Show Gist options
  • Save petevb/9f7971b397b33413a1114acdb541e2eb to your computer and use it in GitHub Desktop.
Save petevb/9f7971b397b33413a1114acdb541e2eb to your computer and use it in GitHub Desktop.
[git FAQ] #windows #git #branch

delete branches no longer on remote (Windows console)

for /f "tokens=1,2,3*" %i in ('git branch -v') do @if "%k"=="[gone]" git branch -d %i

See this in GitHub and want to know which commits are ahead/behind?

image

This is how to confirm those counts

c:\code\ttc-develop (release/34-ahead) > git rev-list --count origin/develop..origin/release/34
                                         7

c:\code\ttc-develop (release/34-ahead) > git rev-list --count origin/release/34..origin/develop
                                         175

This is how to list the commits

c:\code\ttc-develop (release/34-ahead) > git rev-list --left-right origin/develop..origin/release/34
>506770cec7c4c46263f218ce70b46dec51ebcd96
>d9aff5a40ec7eaa32687a4fe1faa5b79b58ad9e9
>7e864f2555fbfbba0be939fea23eff3daca677b5
>87ff8e3e8ff2832f74c1790a1d54c6b8da48a6c5
>d1eaccf94df7cad86b8b47bc414577a0c1095309
>579b5ea13c11dd7b6d11f3c72af92c68250d87ad  --> this is 34.1
>8c8314aa8ceaccf46e555dedf29303192e1ecec6  --> develop

c:\code\ttc-develop (release/34-ahead) > git rev-list --left-right origin/develop..origin/release/34.1
>b9f8f0bfa071fe4bd15ec62d632c486304f99f13
>967f8596b282ed50c8081796501e03444644d629
>75e3d84e7a4b819cf1809fe14a2bc3f9fe1a536a

Then cherry-pick the changes (e.g.)

Note: AFAIK you should only be cherry-picking changes to recover from a mistake that's preventing a "standard" merge, e.g. if you squashed branches.

# ensure you're on latest develop:
git checkout develop
git pull

# create branch off develop to add the fixes: 
git checkout -b fix-the-mess

# pick your missing changes into the new branch:
git cherry-pick b9f8f0bfa071fe4bd15ec62d632c486304f99f13

# … etc., etc., then push to the remote and send a PR to merge into develop

How to list branches that contain a given commit?

From the git-branch manual page:

git branch --contains <commit> Or remote: git branch -r --contains <commit>

Only list branches which contain the specified commit (HEAD if not specified). Implies --list.

Example

c:\code\ttc-develop (release/34-ahead) > git branch --contains 8c8314aa8ceaccf46e555dedf29303192e1ecec6
  contains
  master
  release/34
  fix-the-mess

c:\code\ttc-develop (release/34-ahead) >             

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment