Skip to content

Instantly share code, notes, and snippets.

@sumeet-bansal
Last active March 29, 2023 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sumeet-bansal/68ff0495836ea883d20f9b49b2c7616c to your computer and use it in GitHub Desktop.
Save sumeet-bansal/68ff0495836ea883d20f9b49b2c7616c to your computer and use it in GitHub Desktop.
Misc notes on Git.

To tag a commit and use the commit date for the tag:

git checkout <commit hash>
GIT_COMMITTER_DATE="$(git show --format=%aD  | head -1)" git tag <tag name>

To fix commit timestamps:

git filter-branch --env-filter 'export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"'

To force push a subtree to a remote:

git subtree split --prefix [FOLDER_NAME] -b [BRANCH_NAME]
git push -f origin [LOCAL_BRANCH_NAME]:[REMOTE_BRANCH_NAME]

The filter-branch command I bulk fixed Albert's commits with:

git filter-branch --commit-filter 'if [ "$GIT_AUTHOR_NAME" = "your previous name" ];
  then export GIT_AUTHOR_NAME="your New Name"; export GIT_AUTHOR_EMAIL=new.email@example.com;
  export GIT_COMMITTER_NAME="your New Name"; export GIT_COMMITTER_EMAIL=new.email@example.com
  fi; git commit-tree "$@"'

To make git detect a bunch of renames:

git add . -A

To rebase the last N commits of a branch A onto another branch B

git rebase -i --onto B A~N A
git rebase -i --onto develop sbansal/drop-schema-versions~3 sbansal/drop-schema-versions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment