mirror of
https://github.com/jbranchaud/til
synced 2026-01-17 05:58:01 +00:00
Compare commits
2 Commits
f394ecc055
...
c1f5486660
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1f5486660 | ||
|
|
da17929878 |
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1227 TILs and counting..._
|
||||
_1229 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -293,6 +293,7 @@ _1227 TILs and counting..._
|
||||
- [Resolve A Merge Conflict From Stash Pop](git/resolve-a-merge-conflict-from-stash-pop.md)
|
||||
- [Run A Git Command From Outside The Repo](git/run-a-git-command-from-outside-the-repo.md)
|
||||
- [Set A Custom Pager For A Specific Command](git/set-a-custom-pager-for-a-specific-command.md)
|
||||
- [Shorthand To Force Push A Branch](git/shorthand-to-force-push-a-branch.md)
|
||||
- [Show All Commits For A File Beyond Renaming](git/show-all-commits-for-a-file-beyond-renaming.md)
|
||||
- [Show Changes For Files That Match A Pattern](git/show-changes-for-files-that-match-a-pattern.md)
|
||||
- [Show Changes In The Compose Commit Message View](git/show-changes-in-the-compose-commit-message-view.md)
|
||||
@@ -439,6 +440,7 @@ _1227 TILs and counting..._
|
||||
- [Sleep For A Bit In Async Code](javascript/sleep-for-a-bit-in-async-code.md)
|
||||
- [Sorting Arrays Of Objects With Lodash](javascript/sorting-arrays-of-objects-with-lodash.md)
|
||||
- [Splat Arguments To A Function](javascript/splat-arguments-to-a-function.md)
|
||||
- [Spread Merging Objects Includes Nil Values](javascript/spread-merging-objects-includes-nil-values.md)
|
||||
- [Spread The Rest With ES6](javascript/spread-the-rest-with-es6.md)
|
||||
- [Start Node Process In Specific Timezone](javascript/start-node-process-in-specific-timezone.md)
|
||||
- [String Interpolation With Template Literals](javascript/string-interpolation-with-template-literals.md)
|
||||
|
||||
27
git/shorthand-to-force-push-a-branch.md
Normal file
27
git/shorthand-to-force-push-a-branch.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Shorthand To Force Push A Branch
|
||||
|
||||
If your local version of a branch differs in its history from the matching
|
||||
remote branch, then git will prevent you from pushing. You can override the
|
||||
difference on the remote by force pushing. One way of doing that is with the
|
||||
`--force` flag.
|
||||
|
||||
```bash
|
||||
$ git push --force origin main
|
||||
```
|
||||
|
||||
There is a shorthand for this. [Prefix the branch name with a
|
||||
`+`](https://git-scm.com/docs/git-push#Documentation/git-push.txt---force).
|
||||
|
||||
```bash
|
||||
$ git push origin +main
|
||||
```
|
||||
|
||||
When working in a team context, it is typically a safer bet to use
|
||||
`--force-with-lease` instead of force. That way if the remote contains new
|
||||
changes that you haven't pulled down yet, you will prevent yourself from
|
||||
accidentally overriding them.
|
||||
|
||||
If you feel you must use `--force`, double check what will happen. Avoid
|
||||
accidentally clobbering work that could be hard or impossible to recover.
|
||||
|
||||
[source](https://twitter.com/jbrancha/status/1558861987374780416?s=20&t=D7T_aTBaF97AwOvUnz9Muw)
|
||||
27
javascript/spread-merging-objects-includes-nil-values.md
Normal file
27
javascript/spread-merging-objects-includes-nil-values.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Spread Merging Objects Includes Nil Values
|
||||
|
||||
A handy way to merge two objects together with ES6 JavaScript syntax is to use
|
||||
the [spread
|
||||
operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax).
|
||||
|
||||
```javascript
|
||||
const combinedObj = { ...obj1, ...obj2 };
|
||||
```
|
||||
|
||||
All the key-value pairs from each object are combined into a new object. For
|
||||
any overlapping keys, the last occurrence's value will take precedence.
|
||||
|
||||
That bit about precedence is true for _nil_ values – `null` and `undefined` –
|
||||
as well.
|
||||
|
||||
```javascript
|
||||
const obj1 = { taco: 'bell', hello: 'world', list: [1,2,3] }
|
||||
const obj2 = { burrito: 'house', hello: null, list: undefined }
|
||||
|
||||
const combinedObj = { ...obj1, ...obj2 }
|
||||
//=> { taco: 'bell', hello: null, list: undefined, burrito: 'house' }
|
||||
```
|
||||
|
||||
Notice that even though there are "actual" values for the `hello` and `list`
|
||||
keys in `obj1`, they are overridden by the `null` and `undefined` values in
|
||||
`obj2`.
|
||||
Reference in New Issue
Block a user