A Free Open Source DVCS ”distributed version control system ”
-
- Compares SHA1 sum of modified files.
- Saves the new file as a Whole "easier to retrive lost data"
- Each Snapshot contains references to the files "to save space uses ref. only"
-
- Each Computer has all the history of the project
- Makes it faster and easeir to contribute
- Safer beacuase the data are not onlt on one repo
-
- Everything in Git is CHECKSUMMED "fast ,reliable"
- Uses SHA-1 hash "a 40 hexadecimal char string"
- Easy to recognize corrupted files.
- Modified
- Staged
- Committed
$ sudo apt update
$ sudo apt intsall git
git config --global user.name "John Doe"
git config --global user.email [email protected]
git config --global core.editor nano
git config --global merge.tool meld
git has a really good command manual for each command
$ git help <command>
$ man git <command>
$ git <command> -h #summarized
- Repository
- Index “Staging area”
- working tree “Project tree”
- Commit
- Branch
- Tag
- Master
- Head
$ git init # Intialize an empty/new repository
$ git clone <URL># to Clone/Copy exsiting repository
<URL>
: can be git, shh, http, https, file , etc
-
git rm <file name| wild card>
-
git mv <file directory | file name | wild card> <new directory | new file name>
-
$ git status $ git status -s # Summarized
??
“ untracked ”- A “ staged ”
- M “ Modified staged “
M
“ Modified untracked “
Example:
$ git status $ echo 'I' > README #creates a new file $ git status
-
Stage your files after adding not before
$ git add <files|WildCards>
Example:
$ git add README $ git status $ echo “USE” >> README $ git status $ git add README $ git status
-
A file listing patterns to match them with files in your repositories.
File name “.gitignore”
-
.gitignore
common templates
-
See
man gitignore
for more information
-
-
$ git status $ git diff #diffreneces between commited and modified/untracked $ git diff --staged #diffreneces between commited and modified/tracked/staged
Example 1
$ git commit -am “cleaning the stage” $ echo “Git” >> README $ echo “Git” > Cont.md $ git add README Cont.md $ git diff # $ echo “OSC” > Cont.md $ git status $ git diff
Example 2
$ git commit -am “cleaning the stage” $ echo “1” > file $ git add file && git commit -m “new file” $ echo “2” > file $ git add file $ echo “3” >file $ git diff $ git diff --staged
-
$ git commit $ git commit -m "short Message" $ git commit -am “Your Message” #Stage all untracked files and commit all files in staged area
Example
$ git commit -am “cleaning the stage” $ echo “1” > newfile $ git commit -am “new file” $ git status $ git add newfile && git commit -m “new file” # Change “newfile” and try using commit -am “changed new file”
-
$ git log $ git log -p $ Git log -<number> $ git log --since <date> $ git log --until <date>
<data>
or<number>
EX : “ 2008-01-15” or EX : "2 years 1 day 3 minutes ago"
$ git reset <files>
$ git commit --amend
Used to change your latest log message and to make modifications to the most recent commit
$ git revert <commit> # merge a previous commit with current commit into a new commit
$ git checkout <commit> # move the Head to the specified commit and change the working set to match the commit
$ git checkout <file> # change the file to match the commited version of the file "the Head commit"
$ git reset --soft <commit> # the Head and the branch pointer will move to the specified commit
$ git reset <commit> # the Head and the branch pointer will move to the specified commit and will clear the index
$ git reset --hard <commit> # the Head and the branch pointer will move to the specified commit and will clear the index and reset the working directory to match it
- git reset:
- --soft: uncommit changes, changes are left staged (index).
- --mixed: (default): uncommit + unstage changes, changes are left in working tree.
- --Hard: uncommit + unstage + delete changes, nothing left.
- <commit>:
- SHA1
- Head^,Head@{number}
$ git clone <URL>
- <URL>:
- https://github.com/
- git://github.com/koke/grit.git
- [email protected]:mojombo/grit.git
- /srv/git/project.git
- file:///srv/git/project.git
-
$ git remote $ git remote -v
-
$ git remote add <Name> <URL>
-
$ git fetch <remote> $ git pull <remote> <branch>
-
$ git push <remote> <branch>
$ git branch
$ git branch -a
$ git Checkout <branch name>
$ git branch -d <branches>
-
- Fast-forward
- Recursive “Three Way merge”
- git mergetool
- meld
-
- git rebase
- git daemon:
- base-path=<path>
- export-all
- reuseaddr
- informative-errors
- verbose
- enable=receive-pack
- You can use aliases
- git config --global alias.<name> ‘commands’
$ git config --global alias.serve '!git daemon --base-path=. --export-all --areuseaddr --informative-errors --verbose'
$ git serve