merge vs. rebase“Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.”
| Centralized | Distributed |
|---|---|
|
|
head?
152 commands
111 "plumbing" commands
152 commands
41 "porcelain" commands
21 "essentials" commands
$ git config --global user.name "Santiago Rojo"
$ git config --global user.email santiago.rojo@graion.com
$ git config --global color.ui true
$ git config --global merge.tool meld
$ git init
Initialized empty Git repository in /home/tiagox/KeepGITSimple/.git/
$ git clone http://dev.graion.com/git/keepgitsimple
Cloning into 'keepgitsimple'...
remote: Counting objects: 4665, done.
remote: Compressing objects: 100% (2281/2281), done.
remote: Total 4665 (delta 2715), reused 4136 (delta 2247)
Receiving objects: 100% (4665/4665), 16.39 MiB | 227.00 KiB/s, done.
Resolving deltas: 100% (2715/2715), done.
Checking connectivity... done
all
$ git add .
files
$ git add README.md
patterns
$ git add src/*.java
interactive
$ git add -p
$ git commit
$ git commit -m "Commit message."
add + commit
$ git commit -am "Commit message."
$ git cherry-pick 5123dad9ce82d6a91b2d027015bfe9d907dcda7b
.gitignore.git/info/exclude
.netbeans
.DS_Store
*.o
*.dll
*.class
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: index.html
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: index.html
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# README.md
$ git log
commit 1be40da451afae95451b47bc0d81309f31a65e5b
Author: Santiago Rojo <santiago.rojo@graion.com>
Date: Thu Sep 5 16:49:04 2013 -0300
Add HTML structure to index.html.
commit 5123dad9ce82d6a91b2d027015bfe9d907dcda7b
Author: Santiago Rojo <santiago.rojo@graion.com>
Date: Thu Sep 5 11:00:53 2013 -0300
Add index file.
what's in master but not in development
$ git log development..master
commit 1be40da451afae95451b47bc0d81309f31a65e5b
Author: Santiago Rojo <santiago.rojo@graion.com>
Date: Thu Sep 5 16:49:04 2013 -0300
Add HTML structure to index.html.
$ git config --global alias.gol "log --graph --pretty=format:'%Cred%h%Creset - %C(blue)%an%Creset
%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative"
$ git gol
$ git branch playground
create + switch
$ git checkout -b development
Switched to a new branch 'development'
$ git branch
* development
master
playground
to another branch
$ git checkout playground
Switched to branch 'playground'
... or go anywhere
$ git checkout 5123dad9ce82d6a91b2d027015bfe9d907dcda7b
Note: checking out '5123dad9ce82d6a91b2d027015bfe9d907dcda7b'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at 5123dad... Add index file.
$ git branch -d playground
$ git branch -D playground
$ git stash
$ git stash save "Comments"
$ git stash list
$ git stash apply
$ git stash drop
apply + drop
$ git stash pop
create
$ git tag -a R01 -m "First release"
list
$ git tag
R01
$ git checkout master
Switched to a new branch 'master'
$ git merge feature
$ git merge feature
Updating 306eb60..56a2247
Fast-forward
index.html | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
$ git checkout master
Switched to a new branch 'master'
$ git merge feature
$ git merge feature
Auto-merging index.html
Merge made by the 'recursive' strategy.
index.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
$ git mergetool
$ git commit
Fast-forward
Recursive strategy
$ git checkout master
Switched to a new branch 'master'
$ git rebase feature
$ git rebase feature
First, rewinding head to replay your work on top of it...
Fast-forwarded master to feature.
$ git checkout master
Switched to branch 'master'
$ git rebase feature
$ git rebase feature
First, rewinding head to replay your work on top of it...
Applying: c3
$ git checkout feature
Switched to branch 'feature'
$ git rebase master
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: c4
Applying: c5
Applying: c6
$ git checkout master
Switched to branch 'master'
$ git merge feature
Updating 306eb60..56a2247
Fast-forward
index.html | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
$ git mergetool
$ git rebase --continue
Wrong rebase
Rebase-Merge
$ git remote add graion http://dev.graion.com/git/keepgitsimple
$ git remote
origin
graion
show details
$ git remote graion
git remote show origin
* remote graion
Fetch URL: http://dev.graion.com/git/keepgitsimple
Push URL: http://dev.graion.com/git/keepgitsimple
HEAD branch: master
Remote branches:
development tracked
master tracked
Local branches configured for 'git pull':
development rebases onto remote development
master merges with remote master
Local refs configured for 'git push':
development pushes to development (up to date)
master pushes to master (up to date)
$ git fetch origin
fetch + merge :S
$ git pull origin
fetch + rebase :)
$ git pull origin --rebase
only the first time
$ git push origin local_branch:remote_branch --set-upstream
then just use
$ git push
don't be proud of use
$ git push origin local_branch:remote_branch --force
$ sudo apt-add-repository ppa:pdoes/ppa
$ sudo apt-get update
$ sudo apt-get install git gitk