This notes are from jadi's introdutory course for Git.
- What is Git?
- Git Workspaces
- Report Commands
- File Modification
- Branches
- Git In The Cloud !
- Conflicts
- Tags
- Sign Commites And Tags
- Debug With Git
Git is a Control version software. It's very usefull for control the changes in different version, team work : you can know who made this change and when.
git init
: add git space to folder.
git help Command
: give manual of Command
Space | Function | Command |
---|---|---|
Untracked | Git do nothing with this file and don't track this | |
Stage | the space befor Commit and after Untracked | Add from Untrack to Stage : git add FileName |
Commit | File which existed in Stage can commit (add to Project) | Commit to Project : git commit -m "Message" |
It is great to have more commite with less changes and good message. It help better contribute.
If don't use -m
, terminal open space to write message (so it is requier to commit). (in that window use ctr to handle quite and other func)
git status
: Show situation of files in folder (whether untracked, or had been modifiade or ready to commit)
git log
: Show all the changes (include commite, changes and so on) with user and it's message and time of it. every commite have unique hash.
git show Hash
: Show detail of commite with hash of Hash.
git diff filename
: We can see the changes on file before add to stage space.
git reset filename
: to exite file from stage mode.
git checkout -- filename
: discared change to file where added to stage space and revert changes.
git mv OldFileName.py NewFileName.py
: Change filename (need commit after this command)
git rm filename
: Remove file from git and system.
Suppose we have main project and we want add some features to it. it is risky (and maybe not clean) to work on main file. Git have solution for us, Branches.
git branch
: Show us Branches (And what branch currently we work on)
git branch BranchName
: make BranchName
git checkout BranchName
: Switch to BranchName
git merge BranchName
: Merge BranchName with active branch
git branch -d BranchName
: Delete BranchName
With git we can work with repositories on the net or network but how?
git clone RepoAdress
: it copy the repo to your local drive
from now I will be Master and the first version of coppied source will be Origin
git push origin master
: After Make change to codes where cloned, we can (if have authority) commit our changes to that repo. This command push from origin to master
git pull origin master
: This command commit from origin to master (kind of update local repo regardin to main repo)
Maybe we wanna add some remote repo to git space. we can do it with:
git remote add origin RepoAdress
: This add RepoAdrees as origin.
Then we can push to origin with : git push origin master
What is Fork? When you fork someone project you make copy of project on your account. You can edit it and make request to merge edits to main project.
Sometime we change piece of code and want to push to origin but someone else edit that piece and pushed. This is Conflict and git can't push our code to repo becuse there is conflict between my change and the change have been made. Explain more: suppose someone delete a line in a code and push it to origin. i don't pull it from origin and in my local hard this code haven't been deleted. I make change on the line and wanna push it, clearly it is Conflict. So at first i must pull and then open the code and solve the conflict.
When we release new version we are on master branch (not any other) and have lot of commite. but later how can we back on previouse verison? With Tags
git tags
: Show all tags
git tag -a TagName -m "Message"
: -a : annoate , this add Tagename to currant project. Tags doesn't commit so in the push they don't push normally. We can push them with : git push origin TagName
or push all tags with : git push origin --tags
Olso we can tag on specific commite with git tag -a TagName CommitHash
git tag -l "Tagname"
: Search in the tags
git show TagName
: Show detail of TagName (Messages,Commites and so on)
To come back to previous version (tag) : git checkout TagName
but for changes it is better or maybe neccecory to creat branch and made changes on it with : git checkout -b BranchName
Because it is secure way to show Undoubdetly the commite belong to you.
You have your own secret key (which sign with it) and public key which others know this and when see tags and commite with that key, understand you made this change.
For generate secure sign we use gpg.
gpg --list-keys
Show lists of gpg keys on pc
gpg --list-keys --keyid-format LONG
Show detail of keys
gpg --gen-key
generate new key
In git :
git config --global user.signinkey KEY
This change sign key in git to one We already creat with gpg. But What is KEY? in the image below the phrase in 'sec' line after '/' is KEY. and the below one is public key.
git tag -s TagName -m "Message"
Sign the Tag.
To show tag with sign use git show TagName
To verify tag with sign use git tag -v TagName
git commit -S -m "Message"
Sign commit
If we know piece of code is bug and want to know who made this bug :
git blame FileName
: Show who write each line of code
git blame FileName -L 10(,12)
: Show history of line 10 (lines between 10 and 12 )
Bisect : Binary Search Commite
git bisect start
: Start directory of search
git bisect bad
: Mark currant dir as Bad . We can add HashOfCommit after bad
git bisect good
: Mark currant dir as Good, We can add HashOfCommit after good
and it start binary search to find buggy code.
پ.ن: این متن یک خلاصه از دوره مقدماتی جادی هست که برای تمرین خودم به زبان انگلیسی نوشتم و قطعا خالی از اشکالات گرامری و لغتی نیست. اگه مشکلی بود خوشحال میشم اطلاع بدین. :)