Add file/directory to .gitignore
git rm -r --cached .
git add .
git commit -m "Fix .gitignore files"
git push
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch FILE_NAME_HERE.TXT' --prune-empty --tag-name-filter cat -- --all
git push REPO_NAME_HERE --force --all
git commit --allow-empty -m "Publish branch message"
git push
git reset --hard HEAD^
Change the '3' to be the number of commits you want to undo.
git reset --hard HEAD~3
Char | Action | Example |
---|---|---|
! | Exclude a file or directory | !/js/*.js |
#!/bin/sh
# Run a Powershell script
c:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -ExecutionPolicy RemoteSigned -Command '.git\hooks\pre-commit.ps1'
$cachedChanges = git diff --cached
$banList = @(
"TODO",
"debugger"
)
foreach ($line in $cachedChanges) {
if ($line.StartsWith("diff --git ")){
$currentFile = $line.Split(" ") | Select-Object -Last 1
}
if ($line.StartsWith("+")) {
foreach ($bannedPhrase in $banList) {
if ($line.Contains($bannedPhrase)) {
Write-Output "Can't commit with TODO | Line: '$line' | File: $currentFile"
exit 1
}
}
}
}
exit 0