Git show config options: git config --list --show-origin

From [](

Git Diffing

Diff working tree vs commit: Use '--' for working tree e.g. git difftool --dir-diff HEAD --

Diff staged changes vs working directory: git difftool --dir-diff

Diff staged changes vs HEAD: git difftool --dir-diff --staged

Diff across branches:

git difftool 4.17..bebylon -- /d/Ikrima/src/Public-Development/UnrealEngine/Engine/Source/Runtime/Renderer/Private/BasePassRendering.cpp
git difftool --dir-diff release ~HEAD

Folder history diff or folder diff between two different commits git difftool --dir-diff 27990a4451cf9458b280c9be027af41898721791~1 27990a4451cf9458b280c9be027af41898721791


Create containing all commits in your current branch that are not in the master branch: git format-patch origin/master --stdout

From [](

GitExtensions: filter a set of branches Bebylon* --remotes=upstream/release* --remotes=upstream/dev*

Diff tool config:

Araxis config:

[difftool "araxis"]
path = C:\\Program Files\\Araxis\\Araxis Merge\\compare.exe

[mergetool "Araxis"]
path = C:/Program Files/Araxis/Araxis Merge/Compare.exe
cmd = \"C:/Program Files/Araxis/Araxis Merge/Compare.exe\" \"$REMOTE\" \"$BASE\" \"$LOCAL\" \"$MERGED\"

Merge with force accept theirs:

Use this commands to do that:

git checkout branch_new
git merge -s ours branch_old
git checkout branch_old
git merge branch_new

From [](

Remove a folder/file from history:

You want to nuke commit C and never see it again. You do this: git reset --hard HEAD~1

From [](

For the lightest touch, you can even undo your commit but leave your files and your index: git reset --soft HEAD~1

From [](

Remove all untracked files and directories. (-f is force, -d is remove directories) git clean -fd

Remove ignored files as well git clean -fdx

From [](

Squash/Merge previous two commits: git rebase -i HEAD~2

Then select squash for the second commit From [](

To move folders into a different folders in git: git filter-branch --tree-filter 'mkdir -p /path/to/tmp; mv * /path/to/tmp; mkdir subdir; mv /path/to/tmp/* subdir/' --tag-name-filter cat --prune-empty -- --all

Rebase against another branch overriding conflicts with your own branch changes:

# assuming branch-a is our current version
git rebase -Xtheirs branch-b # <- ours: branch-b, theirs: branch-a

IMPORTANT: -Xtheirs and -Xours is counterintuitive

  • For rebase: -Xtheirs refers to your local current branch that you want to replay ontop of the master branch.
  • For merge: -Xours refers to the local branch.




  • You need to use python 2.7

  • When doing git clone, you have to specify to use client spec git p4 clone //depot/main/BBR/Source . --use-client-spec

    • You can also exlcude paths and have multiple depot paths
  • With different directory structures, you can reformat patch files:

    $ cat patch_file | git am     \
            -p1                 \ # remove 1 leading directory ('static/')
          --directory='lib/'     # prepend 'lib/'
  • You can also cherry pick commits directly (git will automatically resolve the different path )

  • Remember to have your git-p4 repo in a separate directory from your actual p4 directory

  • You can merge unrealted git histories with git merge myotherbranch --allow-unrelated-histories

  • Use these git config -e settings

    skipSubmitEdit = true
    useclientspec = true

More Info

You can use this to sync from perforce to a git and back (it's brittle)


Install instructions

  • Needs python 2.7
  • git config --global alias.p4 !"python 'C:/Program Files (x86)/Git/mingw32/libexec/git-core/git-p4'"


  • Set P4 Vars:

    set P4USER=yourusername
    set P4PASSWD=yourpassword
  • Clone repo: git p4 clone --detect-branches //depot/perforce_software/p4jenkins

  • Submit: git p4 submit