Introduction to git
-
Upload
aleksey-asiutin -
Category
Education
-
view
836 -
download
0
description
Transcript of Introduction to git
Code management problems and VCS review.
Introduction to git.
Aleksey Asiutin
Old good version control system
Working on the website
index.htm
Collaboration
index.html
“Our team” HTML page
Austin Powers came into the play
File changes
Add James Bond
File changes
Dr. Evil is bad
Dr. Evil is good
Merge problem
File changes history
File changes history
VCS Features
● Backup and Recovery● Team Collaboration and Synchronization● History Log● Nonlinear Project Flow● Find a Guy to Blame :)
VCS
CVS
Subversion
mercurial
git
SourceSafe
Centralized VCS
Distributed VCS
Classic VCS working scheme
How git works with files
git configuration
Current repository configsgit action [arguments]
Current user global configsgit config --global user.name aasiutingit config --global user.email [email protected]
view all git configuration variablesgit config --list
git commands structure
general command structuregit action [arguments]
getting helpgit helpgit help <action>
Initialize git repositorygit init
Initialized empty Git repository in
/Users/spu/mygithub/.git/
Clone remote git repository
git clone \ https://github.com/aasiutin/twitter-
api-php.git
cloning into 'twitter-api-php'...
remote: Counting objects: 24, done.
remote: Compressing objects: 100% (16/16), done.
remote: Total 24 (delta 3), reused 21 (delta 2)
Unpacking objects: 100% (24/24), done.
File status Lifecycle
Check git statusgit status
# On branch master
nothing to commit (working directory
clean)
Add README, check git statusgit status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what
will be committed)
#
# README
nothing added to commit but untracked files
present (use "git add" to track)
Start tracking filesgit add README
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: README
git add use casesgit add file1 file2 [file3 ...] #add list of files
git add *.txt #add all txt files in current directory
git add docs/*.txt #add all txt files in docs directory
git add docs/ #add all files in docs directory
git add "*.txt" #add all txt files in the whole project
git add --all #add all files
modify tracked files$ git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## new file: README## Changed but not updated:# (use "git add <file>..." to update what will be committed)## modified: README
Commit changes to git$ git commit
# Please enter the commit message for your changes. Lines starting# with '#' will be ignored, and an empty message aborts the commit.# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## modified: README~~~".git/COMMIT_EDITMSG" 10L, 283C
$ git config --global core.editor [editor]
$ git commit -a -m “Commit message goes here”
Commit changes to git (2)$ git commit -m "Message goes here"
[master]: created 463dc4f: "Message goes here" 2 files changed, 3 insertions(+), 0 deletions(-) create mode 100644 README
Deleting and moving files$ git rm [filename]rm “[filename]”
$ git rm -f [filename] #remove changed file
$ git rm --cached [filename] #remove only from git, but not from filesystem
$ git mv old-name new-name #rename/move file
$ mv old-name new-name$ git rm oldname$ git add new-name
Undo changes$ git commit --amend #modify last commit
$ git reset HEAD [filename] #unstage file, keep changes
$ git checkout HEAD -- [filename] #discard all file changes and return last commit file state
Ignoring files$ cat .gitignore# a comment - this is ignored*.a # no .a files
!lib.a # but do track lib.a, even though# you're ignoring .a files above
/TODO # only ignore the root TODO file, not# subdir/TODO
build/ # ignore all files in the build/# directorydoc/*.txt # ignore doc/notes.txt, but not# doc/server/arch.txt
View changes and commit history$ git diff #view unstaged changes$ git diff --staged #view staged changes
$ git log #view commit history-p--stat--graph--pretty=oneline|short|full|fuller|format--since--untill--before--after
$ git log --pretty=format:”%h - %an” --before=”2 days ago” --after=”2013-04-25”