menu
search
...

some useful git commands

eye-

git rebase

when you want to let your branch be based on the latest commit of the main branch, you can use the following command.

git rebase main

Maybe your commits are more than one, you can use the following command to squash your commits into one.

# squash the last 3 commits
git rebase -i HEAD~3

But there will be some conflicts, you need to resolve them manually. Then you can use the following command to continue the rebase.

git rebase --continue

If you change your mind, you can use the following command to abort the rebase.

git rebase --abort

One more thing, the commit date will be updated to the time when the rebase was executed. What happens if you want to keep the original commit date?

git rebase -i HEAD~3 --committer-date-is-author-date

git rm --cached

For example, if you accidentally push the .env file to your repo, you can use this command to remove it.

git rm --cached .env
git commit -m "Remove .env from version control"

At the same time, you should add .env to your .gitignore file.

# .gitignore
.env
nextjs intercepting routestodo list using react