-
Notifications
You must be signed in to change notification settings - Fork 5
Lecture 03 About git
READ HELP FOR EVERY COMMAND WITH -h
Internet
- a distributed revision control and source code management - http://git-scm.com/book/en/Distributed-Git-Distributed-Workflows
- requires nonlinear development - http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging
- fledged repository with complete history and full version tracking capabilities, not dependent on network access or a central server
- cryptografic autorization of history - no chance to change older version (commit) without propagation to history of repository - http://git-scm.com/book/en/Git-Basics-Viewing-the-Commit-History
- cool - http://www.slideshare.net/cczona/cool-git-tricks
- command line
- local repository
- command line
- local repository
- because of the company where I've been working :)
- local repository
- simple merging
- rebasing
- command line and quality graphic tools at the same time
- be strong and don't use graphic tools!! (with the exception of commits history and merge tools)
$ mkdir git_test
$ cd git_test
$ git status
$ git init / git clone
$ nano test.rb
$ git status - we can see untracked and tracked files
$ git add test.rb
$ git add . # dot '.' means everything
http://git-scm.com/book/en/Customizing-Git-Git-Configuration
$ cat ~/.gitconfig
$ git config
$ git config --global user.name 'Your Name'
$ git config --global user.email you@somedomain.com
$ cat ~/.gitconfig
$ git commit -a
[ADD] Initial commit
added file app.rb
$ git log --oneline
$ git blame app.rb
$ git diff
Git does't numbered each commit as a Subversion, otherwise it creates unique hash. Only six signs from it should be enough to clearly recognize commit in the frame of repository. Each commit, except the first one, has references to his parents ‘^’.
Graphic tool for Unix https://wiki.gnome.org/Gitg
One of the biggest Git advantage is the possibility to take changes back in the case of mistake.
$ git status
$ git log --oneline
$ git reset HEAD^ # mean reset to parent of newest commit
$ git status
$ git log --oneline
- mixed (i don't use)
- soft (default)
- hard (pottencialy dangerous)
READ HELP FOR EVERY COMMAND WITH -h
$ git reset -h
We add new file into and then take it out again
$ git add test.rb $ git reset test.rb $ git rm test.rb
There is a lot of posibilities how we can take the commit back. Use Internet!
Now the question for you. What is the difference between:
$ git reset HEAD^
$ git reset HEAD^^
$ git reset ...some_commit_hash...
$ git reset ...some_commit_hash...^
$ git checkout test.rb # discard changes on some file
Git pocket
$ git stash
$ git stash apply
Git help us with creation of our own development branches and merging them. It’s all on us. (merge, rebase, cherry-pick)
Special remote: origin Special branch: master
$ git branch
$ git checkout -b devel
$ git branch
Make some changes on app.rb.
$ git add README
$ git commit -m ‘[ADD] Readme’
$ ls -la
$ git checkout master
$ ls -la
During merging can this situation show up: Conflicts on the same line of code, which git cannot deal with.
$ git checkout devel
$ echo 'a' > README
$ git add .
$ git commit -m '[MOD] Readme'
$ git checkout master
$ echo 'b' > README
$ git add .
$ git commit -m '[MOD] Readme'
$ git merge devel # ooups!!
I would like to recommend you to use graphic tools for conflicts resolving. http://meldmerge.org/ http://git-scm.com/book/en/Customizing-Git-Git-Configuration
$ git remote
$ git remote add origin ……….
$ git remote
$ git push -u origin master
$ git clone …... $ git remote set-url origin ……….
Download and merge from origin master
$ git pull origin master
Push changes to origin master
$ git push -u origin master
Allows to show every chagnes, even reset. Default expiration time for saving changes is 90 days.
$ git reflog show $ git reset commit
$ git checkout -b feature
$ echo 'a' > README
$ git commit -a ...
$ echo 'a' > README
$ git commit -a ...
$ echo 'a' > README
$ git commit -a ...
$ git rebase -i HEAD^^^
Then choose e, s, s and continue with git hints
Commands to known
$ git init
$ git status
$ git log
$ git log --oneline
$ git add .
$ git commit
$ git stash
$ git stash clear
$ git stash apply
$ git reset HEAD^
$ git log --oneline # and then
$ git reset ..some_commit_hash..
$ git config -h
$ git clone ....
$ git pull origin master
$ git push origin master
$ git checkout -b some_brach
$ git checkout some_branch
$ git merge some_branch
- rebasing - potentially dangerous
- modification of older commits
- squashing commits with rebase
- force push
- cherry-pick (applications of commits among branches)
- gitignore ** Cool templates: https://github.com/github/gitignore
cheat sheet: http://www.git-tower.com/blog/git-cheat-sheet-detail/ documentation: http://git-scm.com/doc basics: http://gitref.org/basic/ mergetool: http://meldmerge.org/ commits history: https://wiki.gnome.org/Gitg