/ notes / misc

GIT

Misc

Reset commit author and author date:

git commit --amend --no-edit --reset-author

Set author and commit date:

set GIT_COMMITTER_DATE="2024-03-23 10:10:00"
git commit --amend --no-edit --date "2024-03-23 10:00:00"

RefLog

Useful to find lost commits. It is a log of all the changes made to the repository, including commits, checkouts, merges, and resets. Example, you can use it to find a commit id of a branch that was deleted and left ‘orphaned’.

git reflog

Line ending

git config --global core.autocrlf true

Move branch pointer to a different commit

:warning: git branch -f <branch-name> <commit-hash>

E.g.: git branch -f mydevbranch 24dc9xxxxxxxxxxxxxxxxxxxx

Reset branch to a specific commit

:warning: :warning: :warning: git reset --hard <commit-hash>

Username (and password) in the URL

** Security risks and concerns, here! Be careful! **

You can specify username and password in the GIT https url. If you clone that way, the url with username and password will be stored in the .git/config file. Be careful!

The following examples use an Azure DevOps Personal Acces Token (PAT). In such a case, username is useless. Only PAT ‘abc…xyz’ is relevant for authentication.


git pull https://fake:abc...xyz@XXXXXX.visualstudio.com/DefaultCollection/XXXXX/_git/XXXXX  

git push https://fake:abc...xyz@XXXXXX.visualstudio.com/DefaultCollection/XXXXX/_git/XXXXX  HEAD

git pull https://fake:abc...xyz@XXXXXX.visualstudio.com/DefaultCollection/XXXXX/_git/XXXXX  HEAD