Git allows you to do a binary search across commits to hunt down the commit that introduced a bug. Given you are currently on your branch's HEAD that is...
...not working as expected, an example workflow could be: git bisect start # Start bisecting git bisect bad # Tag the revision you are currently on (HEAD) as bad. You could also...
...of a file, or a long test file that was split in many. Fortunately, Git offers a special highlighting mode that directs the reader's attention to relevant code parts...
...git diff --color-moved=dimmed-zebra It will dim lines that were moved around without changes, and highlight changed lines. To easily use dimmed-zebra mode, configure an alias: # ~/.gitconfig...
You can convert git commits into patch files. Those can be used to apply to a different repository [1] or by someone else (e.g. sent when sent to them via...
Creating a patch in git Make your changes and commit them. Run git format-patch COMMIT_REFERENCE to convert all commits since the referenced commit (not including it...
...people recovering from Subversion. Get an existing from the server for the first time git clone git@example.com:repositoryname See what's changed git status Check in locally
...good description" Push local commits to the server git push Get and merge updates from the server git pull Stage a file for the next local commit
...Aug 11 09:42:34 2023 +0200 Add Apples as a new fruit diff --git a/app/models/apple.rb b/app/models/apple.rb new file mode 100644 index 0000000..a51cbad --- /dev/null +++ b/app/models/apple.rb...
+ + attr_accessor :type + + def to_s + I18n.t(type, scope: 'fruits.apples') + end +end diff --git a/spec/models/apple_spec.rb b/spec/models/apple_spec.rb new file mode 100644 index 0000000..6b9a90e --- /dev/null +++ b/spec/models/apple_spec.rb...
local LINEAR_ID=$(echo "$1" | grep "[^/]*$" -o) # Extract linear ID from URLs git log --oneline --grep $LINEAR_ID | grep "^[a-z0-9]*" -o | xargs --no-run-if-empty git...
...can use use the command with up to three arguments (just like a regular git show). Example output for linearcommits ABC-165086636 --stat: commit 048054b1df87576f7c59cc0161cc331c44d2ea6b Author: Foo Bar <foo@bar.com>
Browsing the git stash is a bit tricky. Here is how to see the changes without applying them: git command on the console The following will give you the diff...
...of the topmost stash item: git stash show -u But what about other items on the stash? Well, you can list them like this: $ git stash list stash@{0}: WIP...
Git log offers useful options for filtering. This card provides a short overview. By message Only commits that include a specific string in their commit message git log --grep="tracker...
By file Only commits that introduced changes to a specific file git log -- foo.rb bar.rb Note In case the file was renamed or moved the --follow option can be...
...rebase one clean commit interactively onto main without going through each commit individually using git rebase -i main. What it does: Opens an interactive rebase UI to choose squash/edit/fixup for...
...you squash, reorder, edit, or drop commits. Info This is not the same as git rebase -i main, which would rebase your branch onto main, changing its base. Example:
In the source repository, create a patch based on the commit by running git format-patch SHA1_OF_COMMIT~..SHA1_OF_COMMIT # Note the ~ git format-patch HEAD~ # Shortcut...
In the target repository, restore the commit from the patch file with git am -3way path/to.patch Should this fail, you can fall back to only applying the...
Today I got a better understanding of how git works, in particular what git checkout and git reset do. Git basics A commit holds a certain state of a directory...
...commits. You are "on a branch" when HEAD is pointing to a branch. checkout git checkout … tells Git to replace the current state of paths with their state in the...
The linked article found a simple way to rewrite legacy git aliases to make them work with differently named default branches Step 1: Decide which is the most common default...
...branch name of your projects, e.g. master. Define it as the global init.defaultBranch git configuration : git config --global init.defaultBranch master Step 2: Overwrite the value in each project directory that...
Why Rails has multiple schema formats When you run migrations, Rails will write your current database schema into db/schema.rb. This...
...want to find the commits that touched a specific text in a file, use git log -S 'text in the code' -- path/to/file If you use tig you may run a...
...the convert_number_column_value(value) method in active record is traced (simplified output): git log -n 1 --pretty=oneline -S 'convert_number_column_value(value)' -- activerecord/lib/active_record/base.rb ceb33f84933639d3b61aac62e5e71fd087ab65ed Split out...
Sometimes I ran across a GitHub merge request of a gem where it was not completely obvious in which version the change was released. This might be the case for...
...a bugfix PR that you want to add to your project. Git can help you to find the next git tag that was set in the branch. This usually has...
...me or my peer reviewer is able to parse 500k+ lines of code. Fortunately, git has some handy diff options ready: option comment --color-moved=dimmed_zebra Highlight only changes...
To tackle the rename limit mentioned above, update the local or global git configuration. git config diff.renameLimit 9999 Furthermore, I encourage you to further split the diff into...
git shortlog -s -n [commit-range] -n, --numbered Sort output according to the number of commits per author -s, --summary Suppress commit descriptions, only provide commit count [commit-range]
...Manuel Kallenbach 1 Andreas Robecke Alternatives There is a powerful CLI tool called git who...
Sure, you have a project directory – but all of it is tracked by Git. A project's tmp/ directory is usually not tracked, but by definition it is not...
...a related-files/ directory within your project(s). To keep this directory untracked by Git in all your projects, add it to your global .gitignore file with echo related-files...
Sometimes you might need to nest a git-project inside another git-project. The right strategy is to use submodules in this case. How git submodules work Each submodule is...
...a own git repository Once you commit changes in a submodule, the parent repository can link the new sha as its reference You need to take care manually that your...
...dirty WIP commits back into the master as one pretty commit. Squashing commits with git rebase What we are describing here will destroy commit history and can go wrong. For...
...this reason, do the squashing on a separate branch: git checkout -b squashed_feature This way, if you screw up, you can go back to your original branch, make another...
If you are using git submodules in Gitlab CI, you might run into a "The project you were looking for could not be found or you don't have permission...
Gitlab added a feature that new projects are no longer allowed to be cloned inside CI runs of other repositories by default. To fix this
...expected, got commit 'HEAD~3' git switch --detach HEAD~3 git branch # * (HEAD detached at git-hash) # master Hint You can also use the short version git switch -d.
...With git checkout you can achieve the same. Sources Git - git-switch Documentation
Using git fixup helps you to speed up appending changes further back in the git history of your feature branch. Example: git commit --fixup aabbcc # Create a commit with the...
...message "fixup! Commit message of aabbcc" git rebase -i --autosquash master It would be nice if you could use this feature without the -i flag, but until now it seems...
Inspired by recent "git shortcut" cards I figured it would be nice to have one of these for rebasing a few commits onto another branch. The usual notation is prone...
...You may add this rebase-onto function to your ~/.bashrc: function rebase-onto { commit=$(git log --oneline | fzf --prompt 'Select the first commit you want to move' | awk '{print...