Git: Accessing lost commits
Every time you amend
, rebase
or reset
, git commits get "overwritten".
However, git still allows you to checkout those commits using their SHA1, given you can find it.
One option to do this is
git reflog
# or
git reflog show [BRANCH]
This will show a list of all commits the branch has recently pointed to.
Git might garbage collect those commits eventually, but this should only happen after several weeks.
Related cards:
How to push to Git without running CI on GitLab CI, GitHub Actions, or Travis CI
If a project ist configured to spawn CI runners for tests or deployment when pushing to the Repo, a habit of pushing WIP commits regularly may conflict with that.
Here are two solutions that allow you to keep pushing whenever you feel like it.
#...
Git: Revert one or more commits
Reverting a commit means creating a new commit that undoes the old changes.
Imagine the following commit history:
* commit_sha3 [Story-ID 1] Fixup for my feature
* commit_sha2 [Story-ID 5] Other feature
* commit_sha1 [Story-ID 1] My fea...
Configuring Git with .gitconfig
Basic configuration
Please keep this config simple. It should be a starting point for new developers learning Git.
[user]
name = Your Name
email = your.name@domain.com
[branch]
sort = -committerdate
[color]
ui = auto
[color "bra...
Git: Splitting up changes into several commits
Splitting up commits makes the process of reviewing often easier, since you can create several merge requests or review every commit one by one.
So when you find out that you have portions of the code that you initially didn't intend to change o...
Squashing several Git commits into a single commit
This note shows how to merge an ugly feature branch with multiple dirty WIP commits back into the master as one pretty commit.
Squashing commits with git rebase
What we are describing here will destroy commi...
Git: What to do when "git log" does not show commits that touch a file
Let's say you have commits that change a file (and looking at the commit details show you the changes, etc). Now, when you do a git log
you see them, but when you say git log that.file
these commits don't show up? This is for you.
The reason ...
Git: See all unpushed commits or commits that are not in another branch
If you need to find out which of your local commits are not on the remote server do this:
git cherry -v
The -v
option prints out the commit messages. Without it you will see only the SHA1 codes.
You may also compare against another (upstr...
How to set git user and email per directory
I am using git at several places: at work, at university, and at home. I want an own git user/email for each of those places, but I don't want to care setting the values each time I create or clone a new repository.
Git allows for setting user/em...
Getting permanent links to files on Github or Gitlab
Please don't simply copy line number links from Github. The URL usually contains a branch name like master
which will change over time:
https://github.com/makandra/upjs/blob/master/lib/assets/javascripts/up/link.js.coffee#L76
If someon...
GitLab: Git alias for creating a merge request on push
Git allows you to set push options when pushing a branch to the remote.
You can use this to build an alias that automatically pushes a branch and creates a merge request for it.
Put this in your ~/.gitconfig
in the [alias]
section:
mr = ...