Recently studied Puppet's enterprise architecture deployment, complementing its knowledge of git.
Position:
Cd/home/nginxgit Init
Create a simple git repository:
Cd/var/nging.gitgit Clone--bare/home/nginx/var/nginx.git
We build a git learning environment:
Cd/home/nginxgit add *git commit-a-M "init" git remote Origin/var/nginx.gitgit push origin Master:master
Another replica directory:
Git Clone/var/nginx.git/opt/mynginx
At this point, the GIT environment should be built.
Git repository for/var/nginx.git
Git's replica directory is:/home/nginx/opt/mynginx
git syntax Learning:
1: Add files to the Git repository
To operate in one of the replica directories:
Cd/home/nginxtouch 1.txtgit Add 1.txtgit commit-a-m ' Add 1.txt ' git push origin another replica directory: Cd/home/mynginxgit pull Origin —--> Download remote repositories locally, similar to svn up NOTE: Git fetch origin----> Download only the change information, which is equivalent to the previous part of the pull process.
Add and delete changes, and the addition of file operations similar.
2: Create a branch
Cd/home/nginxgit Branch-----> View Branch git branch test-----> New Test branch git checkout test----> Switch to Test Branch
In the Test branch, make a file creation operation:
[[email protected] nginx]# git checkout testswitched to branch ' Test ' [ [email protected] nginx]# touch 10.txt[[email protected] nginx]# git add 10.txt[[email protected] nginx]# git commit -a -m ' Add 10.txt ' [Test e517336] add 10.txt committer: root <[email protected]>your name and email address were configured automatically basedon Your username and hostname. please check that they are accurate. you can suppress this message by setting them explicitly: git config --global user.name "Your name" git config --global user.email [email protected]if the identity used for this commIt is wrong, you can fix it with: git commit --amend --author= ' your name <[email protected]> ' 0 files Changed, 0 insertions (+), 0 deletions (-) create mode 100644 10.txt[[ email protected] nginx]# ls 10.txt 10.txt[[email protected] nginx]# git checkout masterswitched to branch ' master ' [[email protected] nginx]# ls 10.txtls: cannot access 10.txt: No such file or Directory[[email protected] nginx]# git merge test mastertrying simple merge with testAlready up-to-date with masterMerge made by Octopus. 0 files changed, 0 insertions (+), 0 deletions (-) create Mode 100644 10.txt[[email proTected] nginx]# ls 10.txt 10.txt[[email protected] nginx]# git push origin Counting objects: 4, done.Compressing objects: 100% (3/3), done. writing objects: 100% (3/3), 363 bytes, done. total 3 (delta 2), reused 0 (delta 0) unpacking objects: 100% (3/3), done. to /var/ngint.git/ 8c40602. C66f7c2 master -> master can then download the latest file in another copy:[[email protected] nginx]# cd /opt/mynginx/[[email protected] mynginx]# git pull originremote: counting objects: 4, done.remote: compressing objects: 100% (3/3), done.remote: total 3 (delta 2), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. from /var/ngint 8c40602. C66f7c2 master -> origin/masterupdating 8c40602. C66f7c2fast-forward 0 files changed, 0 insertions (+), 0 deletions (-) create mode 100644 10.txt[[email protected] mynginx]#
"Branch Branch Delivery":
[[email protected] nginx]# git branch test2[[email protected] nginx]# git branch * master test test2[[email protected] nginx]# Git push origin test2:test2counting objects: 30, done. compressing objects: 100% (25/25), done. writing objects: 100% (28/28), 2.87 kib, done. total 28 (delta 14), reused 0 (delta 0) unpacking objects: 100% (28/28), done. To /var/ngint.git/ * [new branch] test2 -> test2 [[email protected] mynginx]# git fetch originremote: counting objects: 30, done.remote: Compressing objects: 100% (25/25), done.remote: total 28 (delta 14), reused 0 (delta 0) Unpacking Objects: 100% (28/28), done. from /var/ngint * [new branch] test2 -> origin/test2[[email protected] nginx]# cd /opt/mynginx[[email protected] mynginx]# git checkout -b test2 origin/test2Branch Test2 set up to track remote branch test2 from origin. switched to a new branch ' Test2 ' [[email protected] mynginx]# git Branch master test* test2
Fallback:
1: No fallback for add operation after modification
[[email protected] nginx]# echo "haha" >> 3.txt[[email protected] nginx]# cat 3.txt This is just a test!haha[[email Protected] nginx]# git checkout 3.txt[[email protected] nginx]# cat 3.txt This is just a test! [Email protected] nginx]#
2: Fallback for an add operation already
[[email protected] nginx]# echo "haha" >> 3.txt[[email protected] nginx]# cat 3.txt This is just a test!ha Ha[[email protected] nginx]# git add 3.txt[[email protected] nginx]# cat 3.txt This is just a test!haha[[email protected] nginx]# git reset--hard headhead is now @ 7d31256 add 20.txt[[email protected] nginx]# cat 3.txt This is just a test! [Email protected] nginx]#
3: Fallback for a commit operation
[[email protected] nginx]# echo "Gaga" >> 3.txt[[email protected] nginx]# cat 3.txt this is just a test!this is just a test!hahhhhgaga[[email protected] nginx]# git add 3.txt ;git commit -a -m ' Modify 3.txt ' [master be0ec23] modify 3.txt committer: root <[email protected]>your name and email address were configured automatically basedon your username and hostname. please Check that they are accurate. you can suppress this message by setting them explicitly: git config --global user.name "Your name" git config --global user.email [email protected]if the identity&nBsp;used for this commit is wrong, you can fix it with: git commit --amend --author= ' your name <[email Protected]> ' 1 files changed, 1 insertions (+), 0 deletions (-) [email protected] nginx]# git log | head -20commit be0ec23cb49cc386533ff3512a21690cb89190ccauthor: root <[email protected]>date: fri apr 10 16:33:32 2015 +0800 modify 3.txt[[email protected] nginx]# git revert be0ec23cb49cc386533ff3512a21690cb89190cc[[email Protected] nginx]# cat 3.txtthis is just a test!this is just a test!hahhhh
Resources:
http://my.oschina.net/u/877348/blog/152660
30 minutes of common commands for learning git