GIT Knowledge

CREATE THE GIT SYSTEM
1. Install GIT software (http://git-scm.com/)
2. Create one folder 
Example: d:\learngit
3. start "Git Bash" (Windows in start menu)
4. Input command: git init
5. Register email and name with following command:
git config --global user.email "<email address>"
git config --global user.name "<user name>"

ADD ONE FILE
1. start "Git Bash" (Windows in start menu) 
2. create one file in GIT folder (d:\learngit)
3. input command to put file into temporary area: git add <file name>
4. input command to commit the change to git repository: git commit -m "<comments>"
5. input command to check the git status: git status 

COMMIT ONE CHANGE
1. start "Git Bash" (Windows in start menu)    
2. change the file which has been commit into GIT
3. input command to compare before commit: git diff <file name>
4. input command to put file into temporary area: git add <file name>
5. input command to commit the change to git repository: git commit -m "<comments>"
6. input command to check the git status: git status 

DELETE ONE FILE
1. start "Git Bash" (Windows in start menu)    
2. delete the file which has been commit into GIT
3. input command to put file into temporary area: git rm <file name>
4. input command to commit the change to git repository: git commit -m "<comments>"
5. input command to check the git status: git status 

CHECK OTHER VERSION
1. start "Git Bash" (Windows in start menu)     
2. input command to check all the changes: git log
3. input command to rollback to nearest tag: git reset --hard HEAD^
4. input command to rollback to any tag: git reset --hard <tag id>
Example:
$ git log --pretty=oneline
3628164fb26d48395383f8f31179f24e0882e1e0 append GPL
ea34578d5496d7dd233c827ed32a8cd576c5ee85 add distributed
cb926e7ea50ad11b8f9e909c05226233bf755030 wrote a readme file

$ git reset --hard HEAD^ HEAD is now at ea34578 add distributed

$ git reset --hard 3628164 HEAD is now at 3628164 append GPL

ROLLBACK ONE CHANGE
Not add
1. start "Git Bash" (Windows in start menu)      
2. change the file which has been commit into GIT 
3. input command to compare before commit: git diff <file name>   
4. input command to rollback the change: git checkout -- <file name>

Already Add
1. start "Git Bash" (Windows in start menu)      
2. change the file which has been commit into GIT 
3. input command to compare before commit: git diff <file name>   
4. input command to put file into temporary area: git add <file name> 
5. input command to rollback the change: git reset HEAD <file name>
6. clean the temporary area: git checkout -- <file name>

BRANCH
Create branch
1. start "Git Bash" (Windows in start menu)      
2. input command to create branch: git checkout -b dev
3. input command to check: git branch

Switch branch
1. start "Git Bash" (Windows in start menu)       
2. input command to switch to master branch: git checkout master
3. input command to switch to dev branch: git checkout dev  

Delete branch
1. start "Git Bash" (Windows in start menu)       
2. input command to delete dev branch: git branch -d dev

Merge branch
Fast forward
git-br-ff-merge
1. start "Git Bash" (Windows in start menu)          
2. input command to merge dev to master: git merge dev

No fast forward
git-no-ff-mode
1. start "Git Bash" (Windows in start menu)          
2. input command to merge dev to master: git merge --no-ff dev

Conflict Operation
git-br-conflict-merged
1. start "Git Bash" (Windows in start menu)       
2. input command to create branch: git checkout -b feature1
3. change the file 
4. input command to commit the change to feature1 branch: git add <file name> / git commit -m "change on feature1"
5. input command to switch to master branch: git checkout master
6. change the file 
4. input command to commit the change to master branch: git add <file name> / git commit -m "change on master"
5. input command to merge branch feature1 to master: git merge feature1
The result is failed.
$ git merge feature1
Auto-merging 1.txt
CONFLICT (content): Merge conflict in 1.txt
Automatic merge failed; fix conflicts and then commit the result.
6. input command to find out the conflict: git status
7. change the file
8. input command to commit the change to master branch: git add <file name> / git commit -m "change on master"
9, input command to merge branch feature1 to master: git merge feature1

Temporary save the working area
1. start "Git Bash" (Windows in start menu)       
2, input command to save the work area: git stash
3. input command to check the stach: git stash list
4. input command to recover the work area without delete stach: git stash apply 
5. input command to recover the work area with delete stach: git stash pop
6. input command to delete the work area stash: git stash drop

Destory the branch with merge
1. start "Git Bash" (Windows in start menu)          
2. input command to destroy the branch without merge: git branch -D <branch name>

Push to remote
1. start "Git Bash" (Windows in start menu)          
2. set the origin for remote side: git remote add test toms@192.168.204.15:/opt/git/TTL/Thor
3. input command to push local information to remote: git push origin master

Pull from remote
1. start "Git Bash" (Windows in start menu)       
2. first time, input comand to pull the whole reposity to local: git clone git@github.com:<username>/<git>
Example: git clone git@github.com:tomshenhao/bootstrap.git   
3. input command to pull remote information to local: git pull
Example git pull 
4. set the connection between remote and local branch: git branch --set-upstream <local branch> <remote branch>
Example: git branch --set-upstream dev origin/dev

Create tag
1. start "Git Bash" (Windows in start menu)          
2. input command to find suitable branch: git branch / git checkout <branch>
3. create a tag with current version: git tag <tag name>
Example: git tag v1.0
4. create a tag with pervious version: git tag <tag name> <commit id>
Example 

$ git log --pretty=oneline --abbrev-commit
6a5819e merged bug fix 101
cc17032 fix bug 101
7825a50 merge with no-ff
6224937 add merge
59bc1cb conflict fixed
400b400 & simple
75a857c AND simple
fec145a branch test
d17efd8 remove test.txt
git tag v0.9 6224937
5. input command to check the detail information: git show <tag name>
6. input command to input the description of the tag: git tag -a <tag name>  -m "<tag description>"
Example: git tag -a v1.0 -m "version 1.0"

Push depending on tag
1. start "Git Bash" (Windows in start menu)          
2. input command to push to remote depending on tag: git push origin v1.0
3. input command to push to remote all left tag: git push origin --tags

Delete tag
1. start "Git Bash" (Windows in start menu)          
2. input command to delete tag: git tag -d <tag name>
Example: git tag -d v1.0
3. input command to delete tag remote:
a. delete tag local: git tag -d <tag name>
b. push the delete to remote: git push origin :refs/tags/<tag name>
Example
git tag -d v0.9
git push origin :refs/tags/v0.9

Ignore Files
1. create one file with name: .gitignore
2. Add the ignore file into it
Example:
# Windows:
Thumbs.db
ehthumbs.db
Desktop.ini

# Python:
*.py[cod]
*.so
*.egg
*.egg-info
dist
build

# My configurations:
db.ini
deploy_key_rsa

Setup git server

Method 1 Control the link by key file
1. git client install
2. git command: ssh-keygen -t rsa
3. upload the public key file to linux user home folder .ssh subfolder 
4. copy the context of public key file to authorized_keys file
5. use git client to test: ssh <linux user>@<git server> 
If can login without password, it means success. Otherwise, need to check again.
6. install TortoiseGIT
7. input URL: <linux user>@<git server>:<git project path> to clone project
Example: test@192.168.204.15:/opt/git/TTL/Acquisitions-MyJournal

Method 2 Control the git by username and password
1. in server, change the group of the git folder to "git" group;
2. in server, create everyone an account and put them in "git" group
Shortage: every time checkout or checkin all need to input password of linux user

Setup Git web
1. yum install gitweb
2. change folder name: mv /var/www/git /var/www/gitweb
3. change file /etc/gitweb.conf add following context
our $projectroot = "/opt/git/TTL";

4. change the file /etc/sysconfig/iptables add following context
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

5. change the file /etc/httpd/conf/httpd.conf add following context
<VirtualHost *:80>
    ServerName gitserver
    DocumentRoot /var/www/gitweb
    <Directory /var/www/gitweb>
        Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
        AllowOverride All
        order allow,deny
        Allow from all
        AddHandler cgi-script cgi
        DirectoryIndex gitweb.cgi
    </Directory>
</VirtualHost>

6. input command: chkconfig httpd on 
7. input command: service httpd start
8. check the url: <git server>


Error: git clone http://github.com/Snorby/snorby.git /var/www/snorby
Cloning into '/var/www/snorby'...
fatal: unable to access 'https://github.com/Snorby/snorby.git/': SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Solution export GIT_SSL_NO_VERIFY=true

Comments

Popular posts from this blog

Nginx Proxy & Load Balance & LNMP

Snort+barnyard2+Snorby CentOS 6.5_64 Installation

ORACLE Error