mirror of
https://github.com/mike-rambil/Advanced-Git.git
synced 2026-01-05 17:09:30 -06:00
37 lines
847 B
Markdown
37 lines
847 B
Markdown
[⬅️ Back to Useful Rare Git Commands You Never Heard Of](./useful-rare-git-commands-you-never-heard-of.md)
|
|
|
|
# git replace <old-commit> <new-commit>
|
|
|
|
|
|

|
|
> Temporarily substitute one commit for another.
|
|
|
|
|
|
#### Command
|
|
```sh
|
|
git replace abc123 def456
|
|
```
|
|
|
|
#### Examples
|
|
- **Temporarily replace commit abc123 with def456.**
|
|
|
|
```sh
|
|
git replace abc123 def456
|
|
```
|
|
- **Graft a new parent onto a commit for testing history changes.**
|
|
|
|
```sh
|
|
git replace --graft HEAD~2 HEAD
|
|
```
|
|
|
|
|
|
#### Steps
|
|
1. Run `git replace <old-commit> <new-commit>` to test or patch history.
|
|
|
|
|
|
[➡️ Continue to Next Topic: How to Use git push --force-with-lease Safely](./how-to-use-git-push-force-with-lease-safely.md)
|
|
|
|
---
|
|
|
|
_Author: mike-rambil • Updated: 2024-06-10 • Tags: replace, history_
|