Skip to content

Instantly share code, notes, and snippets.

@fabriciofmsilva
Last active October 9, 2019 16:14
Show Gist options
  • Save fabriciofmsilva/570d08d0b6f9c62ad8ab28e07d006295 to your computer and use it in GitHub Desktop.
Save fabriciofmsilva/570d08d0b6f9c62ad8ab28e07d006295 to your computer and use it in GitHub Desktop.
Git Utils

git commands

Delete local branch

$ git branch -d <branch_name>
$ git branch -D <branch_name>

Delete server branch

$ git push -d <remote_name> <branch_name>

Merge unrelated histories

fatal: refusing to merge unrelated histories
$ git pull origin <branchname> --allow-unrelated-histories

show whole commit history

$ git log --oneline --decorate --color

show history from one tag to another

$ git log 0.0.9..0.0.10 --oneline --decorate --color

show history form tag to head

git log 0.0.9..HEAD --oneline --decorate --color

git stash

$ git stash
$ git stash list
$ git stash pop

git log

git log --pretty=format:"%h%x09%an%x09%ad%x09%s"
// fbc3503 mads    Thu Dec 4 07:43:27 2008 +0000   show mobile if phone is null...   

git log search

git log --grep=<TEXT> --since=1.month --author=<AUTOR>
git log --all-match
git log -- file/path

Good Mensages

  1. Please start your sentences with an uppercase letter
  2. Please don’t edit the generated git messages
  3. Please don’t write “Revert” or “Merge” when you’re not using git revert nor git merge

IDs

# GitHub
Fix issue #123
# JIRA
[JIRA-1234] Fix a problem with the route system when...

Format

Capitalized, short (50 chars or less) summary

More detailed explanatory text, if necessary.  Wrap it to about 72
characters or so.  In some contexts, the first line is treated as the
subject of an email and the rest of the text as the body.  The blank
line separating the summary from the body is critical (unless you omit
the body entirely); tools like rebase can get confused if you run the
two together.

Write your commit message in the imperative: "Fix bug" and not "Fixed bug"
or "Fixes bug."  This convention matches up with commit messages generated
by commands like git merge and git revert.

Further paragraphs come after blank lines.

- Bullet points are okay, too

- Typically a hyphen or asterisk is used for the bullet, followed by a
  single space, with blank lines in between, but conventions vary here

- Use a hanging indent
Let’s start with a few of the re
Summarize changes in around 50 characters or less

More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of the commit and the rest of the text as the body. The
blank line separating the summary from the body is critical (unless
you omit the body entirely); various tools like `log`, `shortlog`
and `rebase` can get confused if you run the two together.

Explain the problem that this commit is solving. Focus on why you
are making this change as opposed to how (the code explains that).
Are there side effects or other unintuitive consequences of this
change? Here's the place to explain them.

Further paragraphs come after blank lines.

 - Bullet points are okay, too

 - Typically a hyphen or asterisk is used for the bullet, preceded
   by a single space, with blank lines in between, but conventions
   vary here

If you use an issue tracker, put references to them at the bottom,
like this:

Resolves: #123
See also: #456, #789

Samples

Make the cached role coherrent with the actual one

When observing the leader running a master role, set the cached role
stored in the state_handler to master as well. Failure to do so
resulted in the manually promoted node to continue running with a
cached 'replica' role. This led to the failure to create replication
slots for the new replicas.

We could do it conditionally, but both reading and writing the role
require the same lock, and the unconditional approach makes the unit tests simpler.
Fix rewind behavior when paused

* Check if we can rewind when deciding to call Postgresql.follow during pause.

Without this the following sequence of events occurs:

1. Manual failover from node, demotion sets need_rewind flag. Rewind is not done because can_rewind is False.
2. Cluster is put into paused mode. Rewind is not attempted because recovery.conf matches.
3. PostgreSQL goes down (pg_ctl stop).
4. Because need_rewind is set PostgreSQL is restarted.
5. Sysadmin is unhappy because Patroni is doing stuff behind his back during pause.

* Allow superuser user to be missing from config for rewind.

In other places a missing superuser authentication section is allowed and we default to libpq's use default OS user with no password. This makes rewind work with a missing superuser configuration.

---

Issue: [#365](https://link/to/issue/365)
Make Source.indexOf(ByteString) significantly faster

Previously the algorithm that did this was extremely inefficient, and had worst case runtime of O(N * S * S) for N is size of the bytestring and S is the number of segments.

The new code runs in O(N * S). It accomplishes this by not starting each search at the first segment, which could occur many times when called by RealBufferedSource.
Convert specs to RSpec 3.1.7 syntax with Transpec

This conversion is done by Transpec 2.3.8 with the following command:
    transpec

* 46 conversions
    from: it { should ... }
      to: it { is_expected.to ... }

* 7 conversions
    from: it { should_not ... }
      to: it { is_expected.not_to ... }

* 2 conversions
    from: it { should have(n).items }
      to: it 'has n dependencies' do expect(subject.size).to eq(n) end

* 2 conversions
    from: obj.should
      to: expect(obj).to

* 2 conversions
    from: obj.stub(:message)
      to: allow(obj).to receive(:message)

* 1 conversion
    from: == expected
      to: eq(expected)

* 1 conversion
    from: it { should have(n).items }
      to: it 'has n feature' do expect(subject.size).to eq(n) end

* 1 conversion
    from: it { should have(n).items }
      to: it 'has n features' do expect(subject.size).to eq(n) end

* 1 conversion
    from: it { should have(n).items }
      to: it 'has n files' do expect(subject.size).to eq(n) end

For more details:
https://github.com/yujinakayama/transpec#supported-conversions

Want to share the git diff you are playing with to another dev?

dev1 exports unstaged changes

git diff > diff.patch

dev1 exports staged changes

git diff --staged > diff.patch

Send patch file via Slack, etc...

dev2 applies changes from the patch file

git apply diff.patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment