In Git we can gracefully revert all changes to the specific commit without using the potentially dangerous git reset command. In this note i am showing how to undo local changes by making a rollback to the specific commit and how to revert a commit that has already been pushed to remote.
git
Git – Remove All Commits – Clear Git History (Local & Remote)
In this article i am showing how to clear Git history by removing all commits. You may need this if you want to delete sensitive data from the history of Git commits. After such cleanup you will have the latest version of your Git repository, but with the one commit only. Be aware that after […]
Git – Config Username & Password – Store Credentials
To connect to a Git repository with authentication over HTTP(S), every time it needs to set a username and password. You can configure Git to remember a username and password by storing them in a remote URL or by using Git credential helper. In this article i am showing how to clone Git repository by […]
Git – Create New Branch
Instead of committing directly in local master branch, a good developer creates a new branch each time he starts working on a new bug or feature. To create a new branch there is a git branch command. Below i will show the examples of how to create a new local branch in Git from another […]
Git – Squash Commits: Merge All Commits in Branch Into One
Each time you are working on a bug or a feature, you create a branch for it. Usually, while working in such temporary branches, you make multiply commits without bothering a lot about commit messages and simply comment the changes with something like “work in progress” or just “WIP”. Before merging such branch into master […]
Git – Checkout Previous Branch
While working with Git, it’s very common to move back and forth between two branches. If you want to checkout the previous branch you was working on, there is no need to type the name of this branch each time. In this short note i’ll show the easy way to switch between two branches in […]
Git – Diff Between Branches
When you are working with multiple branches in Git, it’s important to be able to compare them and contrast the differences. In this short note i will show how to compare two branches in Git using the git diff command. I will show how to git diff between any two branches, e.g. current branch and […]
Git – Diff Staged and Unstaged Files
While working with Git it is often required to check the changes between different areas. Probably everyone knows the git diff, that shows the changes between the Working Directory and the Staging Area (git diff unstaged). But it is also often needed to shows the changes between the Staging Area and the HEAD (git diff […]
Git – Create New Branch and Checkout – In One Command
Each time you want to commit a bug or a feature, you need to create a branch for it. To create a new branch there is a git branch command. After you have created a branch, you need to switch in this branch using a git checkout command. But it is also possible to create […]
Git – Revert File to Previous Commit
Sometimes it happens that you make some changes to a file but later realize that it was a mistake and these changes have to be discarded. In Git you can revert the changes made to a file if you haven’t committed them yet, as well as you can revert a file to any previous commit. […]