Skip to content
Snippets Groups Projects
Commit f14faf68 authored by balameb's avatar balameb
Browse files

Secodn edition with revert, unstage and merge conflicts

parent e3bcc224
No related branches found
No related tags found
No related merge requests found
## Merge Conflicts
- Happen often
- Learning to fix conflicts is hard
- Practice makes perfect
- Force push after fixing conflicts. Be careful!
----------
## Example Plan
1. Checkout a new branch and edit conflicts.rb. Add 'Line4' and 'Line5'.
2. Commit and push
3. Checkout master and edit conflicts.rb. Add 'Line6' and 'Line7' below 'Line3'.
4. Commit and push to master
5. Create a merge request and watch it fail
6. Rebase our new branch with master
7. Fix conflicts on the conflicts.rb file.
8. Stage the file and continue rebasing
9. Force push the changes
10. Finally continue with the Merge Request
----------
## Example 1/2
```
git checkout -b conflicts_branch
# vi conflicts.rb
# Add 'Line4' and 'Line5'
git commit -am "add line4 and line5"
git push origin conflicts_branch
git checkout master
# vi conflicts.rb
# Add 'Line6' and 'Line7'
git commit -am "add line6 and line7"
git push origin master
```
----------
## Example 2/2
Create a merge request on the GitLab web UI. You'll see a conflict warning.
```
git checkout conflicts_branch
git fetch
git rebase master
# Fix conflicts by editing the files.
git add conflicts.rb
# No need to commit this file
git rebase --continue
# Remember that we have rewritten our commit history so we
# need to force push so that our remote branch is restructured
git push origin conflicts_branch -f
```
----------
## Notes
- When to use 'git merge' and when to use 'git rebase'
- Rebase when updating your branch with master
- Merge when bringing changes from feature to master
- Reference: https://www.atlassian.com/git/tutorials/merging-vs-rebasing/
## Undo Commits
- Undo last commit putting everything back into the staging area.
```
git reset --soft HEAD^
```
- Add files and change message with:
```
git commit --amend -m "New Message"
```
- Undo last and remove changes
```
git reset --hard HEAD^
```
- Same as last one but for two commits back
```
git reset --hard HEAD^^
```
**Don't reset after pushing**
----------
## Reset Workflow
1. Edit file again 'edit_this_file.rb'
2. Check status
3. Add and commit with wrong message
4. Check log
5. Amend commit
6. Check log
7. Soft reset
8. Check log
9. Pull for updates
10. Push changes
----------
```
# Change file edit_this_file.rb
git status
git commit -am "kjkfjkg"
git log
git commit --amend -m "New comment added"
git log
git reset --soft HEAD^
git log
git pull origin master
git push origin master
```
----------
## Note
- git revert vs git reset
- Reset removes the commit while revert removes the changes but leaves the commit
- Revert is safer considering we can revert a revert
```
# Changed file
git commit -am "bug introduced"
git revert HEAD
# New commit created reverting changes
# Now we want to re apply the reverted commit
git log # take hash from the revert commit
git revert <rev commit hash>
# reverted commit is back (new commit created again)
```
## Unstage
- To remove files from stage use reset HEAD. Where HEAD is the last commit of the current branch.
```
git reset HEAD <file>
```
- This will unstage the file but maintain the modifications. To revert the file back to the state it was in before the changes we can use:
```
git checkout -- <file>
```
----------
- To remove a file from disk and repo use 'git rm' and to rm a dir use the '-r' flag.
```
git rm '*.txt'
git rm -r <dirname>
```
- If we want to remove a file from the repository but keep it on disk, say we forgot to add it to our .gitignore file then use --cache.
```
git rm <filename> --cache
```
Loading
Loading
@@ -200,6 +200,36 @@
data-charset="iso-8859-15">
</section>
 
<section data-markdown>
# Merge Conflicts
</section>
<section data-markdown="content/merge_conflicts.md"
data-separator="^\n\n\n"
data-separator-vertical="^----------"
data-separator-notes="^Note:"
data-charset="iso-8859-15">
</section>
<section data-markdown>
# Revert and Unstage
</section>
<section data-markdown="content/unstage.md"
data-separator="^\n\n\n"
data-separator-vertical="^----------"
data-separator-notes="^Note:"
data-charset="iso-8859-15">
</section>
<section data-markdown="content/revert.md"
data-separator="^\n\n\n"
data-separator-vertical="^----------"
data-separator-notes="^Note:"
data-charset="iso-8859-15">
</section>
 
<section data-markdown>
# Questions
Loading
Loading
0 info it worked if it ends with ok
1 verbose cli [ '/Users/kali/.nvm/versions/node/v5.0.0/bin/node',
1 verbose cli '/Users/kali/.nvm/versions/node/v5.0.0/bin/npm',
1 verbose cli 'rebuild',
1 verbose cli 'node-sass' ]
2 info using npm@3.3.6
3 info using node@v5.0.0
4 info readInstalled object
5 verbose rebuild path, id [ '/Users/kali/Desktop/training/eh-session/node_modules/node-sass',
5 verbose rebuild 'node-sass@3.3.3' ]
6 verbose rebuild path, id [ '/Users/kali/Desktop/training/eh-session/node_modules/grunt-sass/node_modules/node-sass',
6 verbose rebuild 'node-sass@3.4.2' ]
7 silly rebuild set [ '/Users/kali/Desktop/training/eh-session/node_modules/node-sass',
7 silly rebuild set '/Users/kali/Desktop/training/eh-session/node_modules/grunt-sass/node_modules/node-sass' ]
8 info build /Users/kali/Desktop/training/eh-session/node_modules/node-sass
9 info lifecycle node-sass@3.3.3~preinstall: node-sass@3.3.3
10 silly lifecycle node-sass@3.3.3~preinstall: no script for preinstall, continuing
11 info linkStuff node-sass@3.3.3
12 silly linkStuff node-sass@3.3.3 has /Users/kali/Desktop/training/eh-session/node_modules as its parent node_modules
13 verbose linkBins node-sass@3.3.3
14 verbose link bins [ { 'node-sass': 'bin/node-sass' },
14 verbose link bins '/Users/kali/Desktop/training/eh-session/node_modules/.bin',
14 verbose link bins false ]
15 verbose linkMans node-sass@3.3.3
16 verbose rebuildBundles node-sass@3.3.3
17 verbose rebuildBundles [ '.bin',
17 verbose rebuildBundles 'async-foreach',
17 verbose rebuildBundles 'chalk',
17 verbose rebuildBundles 'cross-spawn',
17 verbose rebuildBundles 'gaze',
17 verbose rebuildBundles 'get-stdin',
17 verbose rebuildBundles 'glob',
17 verbose rebuildBundles 'meow',
17 verbose rebuildBundles 'mkdirp',
17 verbose rebuildBundles 'nan',
17 verbose rebuildBundles 'node-gyp',
17 verbose rebuildBundles 'npmconf',
17 verbose rebuildBundles 'request',
17 verbose rebuildBundles 'sass-graph' ]
18 info lifecycle node-sass@3.3.3~install: node-sass@3.3.3
19 verbose lifecycle node-sass@3.3.3~install: unsafe-perm in lifecycle true
20 verbose lifecycle node-sass@3.3.3~install: PATH: /Users/kali/.nvm/versions/node/v5.0.0/lib/node_modules/npm/bin/node-gyp-bin:/Users/kali/Desktop/training/eh-session/node_modules/node-sass/node_modules/.bin:/Users/kali/Desktop/training/eh-session/node_modules/.bin:/Users/kali/.rvm/gems/ruby-2.2.4/bin:/Users/kali/.rvm/gems/ruby-2.2.4@global/bin:/Users/kali/.rvm/rubies/ruby-2.2.4/bin:/Users/kali/.nvm/versions/node/v5.0.0/bin://anaconda/bin:/usr/local/sbin:/usr/local/bin:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/go/bin:/usr/local/MacGPG2/bin:/Applications/Postgres.app/Contents/Versions/9.3/bin:/Users/kali/.rvm/bin
21 verbose lifecycle node-sass@3.3.3~install: CWD: /Users/kali/Desktop/training/eh-session/node_modules/node-sass
22 silly lifecycle node-sass@3.3.3~install: Args: [ '-c', 'node scripts/install.js' ]
23 silly lifecycle node-sass@3.3.3~install: Returned: code: 0 signal: null
24 info lifecycle node-sass@3.3.3~postinstall: node-sass@3.3.3
25 verbose lifecycle node-sass@3.3.3~postinstall: unsafe-perm in lifecycle true
26 verbose lifecycle node-sass@3.3.3~postinstall: PATH: /Users/kali/.nvm/versions/node/v5.0.0/lib/node_modules/npm/bin/node-gyp-bin:/Users/kali/Desktop/training/eh-session/node_modules/node-sass/node_modules/.bin:/Users/kali/Desktop/training/eh-session/node_modules/.bin:/Users/kali/.rvm/gems/ruby-2.2.4/bin:/Users/kali/.rvm/gems/ruby-2.2.4@global/bin:/Users/kali/.rvm/rubies/ruby-2.2.4/bin:/Users/kali/.nvm/versions/node/v5.0.0/bin://anaconda/bin:/usr/local/sbin:/usr/local/bin:/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/go/bin:/usr/local/MacGPG2/bin:/Applications/Postgres.app/Contents/Versions/9.3/bin:/Users/kali/.rvm/bin
27 verbose lifecycle node-sass@3.3.3~postinstall: CWD: /Users/kali/Desktop/training/eh-session/node_modules/node-sass
28 silly lifecycle node-sass@3.3.3~postinstall: Args: [ '-c', 'node scripts/build.js' ]
29 silly lifecycle node-sass@3.3.3~postinstall: Returned: code: 1 signal: null
30 info lifecycle node-sass@3.3.3~postinstall: Failed to exec postinstall script
31 verbose stack Error: node-sass@3.3.3 postinstall: `node scripts/build.js`
31 verbose stack Exit status 1
31 verbose stack at EventEmitter.<anonymous> (/Users/kali/.nvm/versions/node/v5.0.0/lib/node_modules/npm/lib/utils/lifecycle.js:233:16)
31 verbose stack at emitTwo (events.js:87:13)
31 verbose stack at EventEmitter.emit (events.js:172:7)
31 verbose stack at ChildProcess.<anonymous> (/Users/kali/.nvm/versions/node/v5.0.0/lib/node_modules/npm/lib/utils/spawn.js:24:14)
31 verbose stack at emitTwo (events.js:87:13)
31 verbose stack at ChildProcess.emit (events.js:172:7)
31 verbose stack at maybeClose (internal/child_process.js:818:16)
31 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
32 verbose pkgid node-sass@3.3.3
33 verbose cwd /Users/kali/Desktop/training/eh-session
34 error Darwin 15.5.0
35 error argv "/Users/kali/.nvm/versions/node/v5.0.0/bin/node" "/Users/kali/.nvm/versions/node/v5.0.0/bin/npm" "rebuild" "node-sass"
36 error node v5.0.0
37 error npm v3.3.6
38 error code ELIFECYCLE
39 error node-sass@3.3.3 postinstall: `node scripts/build.js`
39 error Exit status 1
40 error Failed at the node-sass@3.3.3 postinstall script 'node scripts/build.js'.
40 error This is most likely a problem with the node-sass package,
40 error not with npm itself.
40 error Tell the author that this fails on your system:
40 error node scripts/build.js
40 error You can get their info via:
40 error npm owner ls node-sass
40 error There is likely additional logging output above.
41 verbose exit [ 1, true ]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment