Skip to content

Commit 1f0598b

Browse files
committed
what is rebase
1 parent 047d85b commit 1f0598b

10 files changed

+127
-54
lines changed

Git-and-Github/delete-a-commit-from-Github.md

+7-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ And there I somehow made 2 commits, and pushed them.
66

77
After going back to source branch, subsequent rake gen_deploy will give this error:
88

9-
``failed to push some refs to 'git@github.com:samwize/samwize.github.com'``
9+
`failed to push some refs to 'git@github.com:samwize/samwize.github.com'`
1010

1111
I don’t really understand why.
1212

@@ -16,15 +16,15 @@ But I knew I shouldn’t push the 2 commits in the first place.
1616

1717
Firstly, find out the comit that you want to revert back to.
1818

19-
``git log``
19+
`git log`
2020

2121
For example, commit 7f6d03 was before the 2 wrongful commits.
2222

23-
press q to exit from ``git log``
23+
press q to exit from `git log`
2424

2525
Force push that commit as the new master:
2626

27-
``git push origin +7f6d03:master``
27+
`git push origin +7f6d03:master`
2828

2929
### The + is interpreted as forced push.
3030

@@ -38,9 +38,6 @@ You can also use git reset to undo things. Then force push.
3838

3939
Source - [https://samwize.com/2014/01/15/how-to-remove-a-commit-that-is-already-pushed-to-github/](https://samwize.com/2014/01/15/how-to-remove-a-commit-that-is-already-pushed-to-github/)
4040

41-
42-
43-
4441
## To delete a commit from Github - my earlier note, but should work still now
4542

4643
https://stackoverflow.com/questions/10817906/delete-a-commit-from-github?lq=1
@@ -49,20 +46,18 @@ https://stackoverflow.com/questions/10817906/delete-a-commit-from-github?lq=1
4946
git reset --hard <sha-commit-name-to-go-back-to>
5047

5148
git push -f origin HEAD^:master
52-
5349
```
5450

55-
In first command for "**sha-commit-name-to-go-back-to**" - I copied-and-pasted, the the SHA Key (click on the that specific commit, and then on the right side of the page).
51+
In first command for "**sha-commit-name-to-go-back-to**" - I copied-and-pasted, the the SHA Key (click on the that specific commit, and then on the right side of the page).
5652

5753
This commit was named as “second commit” and after the above 2 commands the entire commit and also another commit (named “third commit”) was deleted. Meaning, the above 2 commands will delete all commits starting from the SHA Key and any forward commit.
5854

5955
But then, when I added the correct version of the full project (by following the above 3 steps) – all the previous commit came right back.
6056

6157
Have to study in moer detail (as of 26-May-2014) to get the correct solution be able to delete a single commit only.
6258

63-
6459
Specially Note, as per the above link, when I ran the below 2 commands
6560

66-
``git rebase -i HEAD~2`` and then ``git push origin +master`` after running the above 2, my Project got completely messed up and went back to much backwards state.
61+
`git rebase -i HEAD~2` and then `git push origin +master` after running the above 2, my Project got completely messed up and went back to much previous state.
6762

68-
### The + is interpreted as forced push.
63+
### The + is interpreted as forced push.

Git-and-Github/git-merge.png

8.03 KB
Loading

Git-and-Github/git-rebase-2.png

7.56 KB
Loading

Git-and-Github/git-rebase-3.png

6.36 KB
Loading

Git-and-Github/git-rebase.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
In Git, there are two main ways to integrate changes from one branch into another: the merge and the rebase
2+
3+
Git’s rebase command reapplies your changes onto another branch. As opposed to merging, which pulls the differences from the other branch into yours, rebasing switches your branch’s base to the other branch’s position and walks through your commits one by one to apply them again.
4+
5+
Let’s look at an example. While working on a branch named login, based on the master branch, one of your team members pushed some changes to master. You need these changes to finish the login feature in your branch.
6+
7+
Merging the master branch back into yours would result in a merge commit, which includes the changes between both branches and exists to show where a merge occured. We won’t need to know when we merged the master into the login branch in the future. Instead, we’d like to pretend that all commits on the login branch happened based on the new state of the master branch.
8+
9+
<img src="git-rebase.png">
10+
11+
Git’s rebase command temporarily rewinds the commits on your current branch, pulls in the commits from the other branch and reapplies the rewinded commits back on top. By switching the current This bases the current branch onto the other branch.
12+
13+
`$ git rebase master`
14+
15+
It’s as if you didn’t start working in the login branch before the commits you pulled in were made. You can also pull with rebase so you don’t have to switch out of your current branch.
16+
17+
## More Explanation
18+
19+
How the `git merge` works - It performs a three-way merge between the two latest branch snapshots (C3 and C4) and the most recent common ancestor of the two (C2), creating a new snapshot (and commit).
20+
21+
<img src="git-merge.png">
22+
23+
However in `git rebase` you can take the patch of the change that was introduced in C4 and reapply it on top of C3. In Git, this is called rebasing. With the rebase command, you can take all the changes that were committed on one branch and replay them on another one.
24+
25+
In this example, you’d run the following:
26+
27+
```js
28+
$ git checkout experiment
29+
$ git rebase master
30+
First, rewinding head to replay your work on top of it...
31+
Applying: added staged command
32+
```
33+
34+
### It works by going to the common ancestor of the two branches (the one you’re on and the one you’re rebasing onto), getting the diff introduced by each commit of the branch you’re on, saving those diffs to temporary files, resetting the current branch to the same commit as the branch you are rebasing onto, and finally applying each change in turn.
35+
36+
<img src="git-rebase-2.png">
37+
38+
At this point, you can go back to the master branch and do a fast-forward merge.
39+
40+
```js
41+
$ git checkout master
42+
$ git merge experiment
43+
```
44+
45+
<img src="git-rebase-2.png">
46+
47+
#### Now, the snapshot pointed to by C4' is exactly the same as the one that was pointed to by C5 in the merge example. There is no difference in the end product of the integration, but rebasing makes for a cleaner history. If you examine the log of a rebased branch, it looks like a linear history: it appears that all the work happened in series, even when it originally happened in parallel.
48+
49+
Often, you’ll do this to make sure your commits apply cleanly on a remote branch — perhaps in a project to which you’re trying to contribute but that you don’t maintain. In this case, you’d do your work in a branch and then rebase your work onto origin/master when you were ready to submit your patches to the main project. That way, the maintainer doesn’t have to do any integration work — just a fast-forward or a clean apply.
50+
51+
#### Note that the snapshot pointed to by the final commit you end up with, whether it’s the last of the rebased commits for a rebase or the final merge commit after a merge, is the same snapshot – it’s only the history that is different. Rebasing replays changes from one line of work onto another in the order they were introduced, whereas merging takes the endpoints and merges them together.
52+
53+
### Additional Resources
54+
55+
[https://jeffkreeftmeijer.com/git-rebase/](https://jeffkreeftmeijer.com/git-rebase/)
56+
57+
[https://git-scm.com/book/en/v2/Git-Branching-Rebasing](https://git-scm.com/book/en/v2/Git-Branching-Rebasing)
58+
59+
[https://blog.algolia.com/master-git-rebase/](https://blog.algolia.com/master-git-rebase/)

Git-and-Github/git-rebase.png

47.6 KB
Loading
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
### How GridFS works and why we would need this
2+
3+
Mongodb provides us with a very efficient way to store files directly in db rather than in file system. So basically what this means is, suppose you need to store an image file or an audio or video file you can directly store that in mongodb itself.
4+
5+
However, MongoDB is a NoSQL document-database, meaning it stores the data in the form of documents. Default document size limit in MongoDB is 16MB. That is if you want to store files upto 16MB then it’s not a big deal. But to store heavy files of size exceeding 16MB, MongoDB provides a module called GridFS. What GridFS does is that it divides your files into the chunks of 255kB (initially it was 256kB) and then stores it into the database.
6+
7+
What exactly happens is it creates two collections in your database instance that you are currently using. In one collection, it stores the 255kB chunks of the files and the other collection is a document that contains the meta-data of your file.
8+
9+
[Official document page](https://docs.mongodb.com/manual/core/gridfs/)
10+
11+
To use with GridFS and multer for file upload functionality, two other very important packages we would use are `multer-gridfs-storage` and `gridfs-stream` like so.
12+
13+
```
14+
const GridFsStorage = require('multer-gridfs-storage');
15+
16+
const Grid = require('gridfs-stream');
17+
```
18+
19+
Why multer-gridfs-storage - https://github.com/devconcept/multer-gridfs-storage/wiki/Using-generator-functions - GridFS storage engine for Multer to store uploaded files directly to MongoDb.
20+
21+
gridfs-stream is required for streaming files to and from MongoDB GridFS.
22+
23+
The gridfs-stream module exports a constructor that accepts an open mongodb-native db and the mongodb-native driver you are using. The db must already be opened before calling **createWriteStream** or **createReadStream**.

MongoDB/insert-data-into-mongodb-collection.md

+11-13
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@ Say my user scheme is as below
55
```js
66
var UserSchema = new Schema({
77
username: {
8-
type: String,
9-
unique: true,
10-
required: true
11-
},
8+
type: String,
9+
unique: true,
10+
required: true
11+
},
1212
password: {
13-
type: String,
14-
required: true
15-
}
13+
type: String,
14+
required: true
15+
}
1616
});
17-
1817
```
1918

20-
And running ``db.users.find().pretty()`` gives me the below result in terminal
19+
And running `db.users.find().pretty()` gives me the below result in terminal
2120

2221
```
2322
{
@@ -32,10 +31,9 @@ And running ``db.users.find().pretty()`` gives me the below result in terminal
3231
"password" : "$2a$10$HyXCD5.4U/0CvZHq9SDQ0uxD12BQ46yVAHu18lRRVEQZB3uyHXgy.",
3332
"__v" : 0
3433
}
35-
3634
```
3735

38-
### Now use ``db.users.insert`` to add a new document (i.e. record ) into this users collection run the below in terminal
36+
### Now use `db.users.insert` to add a new document (i.e. record ) into this users collection run the below in terminal
3937

4038
```
4139
db.users.insert(
@@ -47,8 +45,8 @@ db.users.insert(
4745
)
4846
```
4947

50-
#### Note, I dont have to provide a separate _id field as mongodb will generate that by itself
48+
#### Note, I dont have to provide a separate \_id field as mongodb will generate that by itself
5149

5250
And the part "$2a$10$HyXCD5.4U/0CvZHq9SDQ0uxD12BQ46yVAHu18lRRVEQZB3uyHXgy." is what I generated a hashed version of a plaintext password using the online tool [https://bcrypt-generator.com/](https://bcrypt-generator.com/) . Because in my actual app (where this was implemented) I used bcrypt to hash the password.
5351

54-
But I could very well used "123" in the mongo shell.
52+
But I could very well used "123" in the mongo shell.

MongoDB/referencing-another-schema-in-Mongoose.md

+21-25
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,34 @@
44

55
Take an example of a social-network [https://github.com/PrinceDavis/mongodb-joins](https://github.com/PrinceDavis/mongodb-joins). The repo contains a working webservice that allow you to create users, posts, and comments. You can also fetch users, their friends, posts, post creators and comments.
66

7-
Here's my user model - ``src/models/user/user.js``
7+
Here's my user model - `src/models/user/user.js`
88

99
```js
1010
const Schema = new mongoose.Schema({
1111
fullname: {
12-
type: String,
13-
required: true
14-
},
12+
type: String,
13+
required: true
14+
},
1515
username: {
16-
type: String,
17-
required: true
18-
},
16+
type: String,
17+
required: true
18+
},
1919
friends: [
20-
{
21-
type: mongoose.Schema.ObjectId,
22-
ref: 'User'
23-
}
20+
{
21+
type: mongoose.Schema.ObjectId,
22+
ref: "User"
23+
}
2424
]
25-
})
26-
27-
module.exports = mongoose.model('User', Schema)
25+
});
2826

27+
module.exports = mongoose.model("User", Schema);
2928
```
3029

3130
Here I created a mongoose schema for user data, notice that the type of friends is itself a type of ObjectId and has a ref property, this is how mongoose perform collection linking or join or relationships. Each user would have a friends array which would hold id values of other friends that they are friends with. back in the all method in our controller where we call populate function on UserModel we are telling mongoose to swap the id values for the real collection that those values represent.
3231

33-
3432
#### And then in my src/models/post/post.js
3533

36-
A post has comment and a user who created it. That is, a Post belong to a User, hence it's 'creator' property will have its ref to ``User``
34+
A post has comment and a user who created it. That is, a Post belong to a User, hence it's 'creator' property will have its ref to `User`
3735

3836
```js
3937
const Schema = new mongoose.Schema({
@@ -44,15 +42,16 @@ const Schema = new mongoose.Schema({
4442

4543
module.exports = mongoose.model('Post', Schema)
4644
```
47-
### And this is my comment.js file. A comment belog to a Post, hence the 'post' property will have its ref to ``Post``
45+
46+
### And this is my comment.js file. A comment belog to a Post, hence the 'post' property will have its ref to `Post`
4847
4948
```js
5049
const Schema = new mongoose.Schema({
51-
post: { type: mongoose.Schema.ObjectId, ref: 'Post' },
50+
post: { type: mongoose.Schema.ObjectId, ref: "Post" },
5251
body: { type: String, required: true }
53-
})
52+
});
5453

55-
module.exports = mongoose.model('Comment', Schema)
54+
module.exports = mongoose.model("Comment", Schema);
5655
```
5756
5857
#### The ref attribute
@@ -61,19 +60,16 @@ DBRefs have the following fields:
6160
6261
$ref - The $ref field holds the name of the collection where the referenced document resides.
6362
64-
$id - The $id field contains the value of the _id field in the referenced document.
63+
$id - The $id field contains the value of the \_id field in the referenced document.
6564
6665
$db - Optional.
6766
6867
Contains the name of the database where the referenced document resides.
6968
7069
Only some drivers support $db references.
7170
72-
73-
7471
https://docs.mongodb.com/manual/reference/database-references/#dbrefs
7572
76-
7773
### More sources to read about
7874
79-
[https://docs.mongodb.com/manual/reference/database-references/](https://docs.mongodb.com/manual/reference/database-references/)
75+
[https://docs.mongodb.com/manual/reference/database-references/](https://docs.mongodb.com/manual/reference/database-references/)

Redux/dispatch.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
https://redux.js.org/api-reference/store#dispatch
22

3-
dispatch() is one of the 4 methods of redux-store. dispatch() is the method used to dispatch actions and trigger state changes to the store. ``react-redux`` is simply trying to give you convenient access to it.
3+
dispatch() is one of the 4 methods of redux-store. dispatch() is the method used to dispatch actions and trigger state changes to the store. `react-redux` is simply trying to give you convenient access to it. So the way we take `actions` to the `store` is `dispatch`
44

55
```
66
​getState()​
@@ -11,6 +11,7 @@ dispatch() is one of the 4 methods of redux-store. dispatch() is the method used
1111
1212
​replaceReducer(nextReducer)​
1313
```
14+
1415
## dispatch(action)​
1516

1617
Dispatches an action. This is the only way to trigger a state change.
@@ -24,9 +25,10 @@ Returns
2425
(Object): The dispatched action (see notes).
2526

2627
## Object serialization
28+
2729
Object serialization is the process of converting an object’s state to a string from which it can later be restored. ECMAScript 5 provides native functions JSON.stringify() and JSON.parse() to serialize and restore JavaScript objects. These functions use the JSON data interchange format.
2830

29-
## My working example - ../brad-mern-shopping-list/client/src/actions/itemActions.js
31+
## My working example - ../brad-mern-shopping-list-Redux-No-Edit-Functionality/client/src/actions/itemActions.js
3032

3133
```js
3234
import axios from 'axios';
@@ -51,12 +53,12 @@ export const setItemsLoading = item => {
5153
type: ITEMS_LOADING
5254
}
5355
}
54-
5556
```
57+
5658
I am using dispatch() to send the type along with the data that we get from the axios request to the backend. The main function (addItem) dispatches another function ( setItemsLoading ). This second function is called a thunk, and it returns the object/action. In the context of redux-thunk, a thunk is a second function that performs delayed logic by being asynchronously returned by a first function.
5759

5860
This double function strategy allows us to wait for an asynchronous operation (like fetching data) to complete, and then the action is returned by the thunk.
5961

6062
The plain data flows in a typical Redux is like this >> dispatch(action) -> reducer -> new state -> re-render
6163

62-
The adjusted order, including reducers, is: dispatch ➡️ action creator ➡️ thunk ➡️ action ➡️ reducer.
64+
The adjusted order, including reducers, is: dispatch ➡️ action creator ➡️ thunk ➡️ action ➡️ reducer.

0 commit comments

Comments
 (0)