最近在研究puppet的企业架构部署,补充下自己的git方面的知识。
位置:
cd /home/nginx git init
建立单纯的git仓库:
cd /var/nging.git git clone --bare /home/nginx /var/nginx.git
我们搭建git学习环境:
cd /home/nginx git add * git commit -a -m "init" git remote origin /var/nginx.git git push origin master:master
另一个副本目录:
git clone /var/nginx.git /opt/mynginx
至此,git环境应搭建完毕。
git仓库为/var/nginx.git
git的副本目录为:/home/nginx /opt/mynginx
git语法学习:
1:往git仓库中添加文件
在其中一个副本目录中操作:
cd /home/nginx touch 1.txt git add 1.txt git commit -a -m ‘add 1.txt‘ git push origin 另一个副本目录: cd /home/mynginx git pull origin —-->把远程的仓库中的下载到本地,类似的svn up 注意: git fetch origin ---->只下载变更信息,相当于pull的过程的前一部分。
增删改,和添加文件操作类似。
2: 创建分支
cd /home/nginx git branch ----->查看分支 git branch test ----->新建test分支 git checkout test ---->切换到test分支
在test分支中,进行一次创建文件的操作:
[[email protected] nginx]# git checkout test Switched 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 based on 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 master Switched to branch ‘master‘ [[email protected] nginx]# ls 10.txt ls: cannot access 10.txt: No such file or directory [[email protected] nginx]# git merge test master Trying simple merge with test Already up-to-date with master Merge 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 这时就能在另一个副本,下载最新文件了: [[email protected] nginx]# cd /opt/mynginx/ [[email protected] mynginx]# git pull origin remote: 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/master Updating 8c40602..c66f7c2 Fast-forward 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 10.txt [[email protected] mynginx]#
“branch分支传递”:
[[email protected] nginx]# git branch test2 [[email protected] nginx]# git branch * master test test2 [[email protected] nginx]# git push origin test2:test2 Counting 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 origin remote: 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/test2 Branch test2 set up to track remote branch test2 from origin. Switched to a new branch ‘test2‘ [[email protected] mynginx]# git branch master test * test2
回退:
1:修改完后没有add操作的回退
[[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:已经add操作的回退
[[email protected] nginx]# echo "haha" >> 3.txt [[email protected] nginx]# cat 3.txt this is just a test! haha [[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 HEAD HEAD is now at 7d31256 add 20.txt [[email protected] nginx]# cat 3.txt this is just a test! [[email protected] nginx]#
3:已经commit操作的回退
[[email protected] nginx]# echo "gaga" >> 3.txt [[email protected] nginx]# cat 3.txt this is just a test! this is just a test! hahhhh gaga [[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 based on 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]>‘ 1 files changed, 1 insertions(+), 0 deletions(-) [[email protected] nginx]# git log | head -20 commit be0ec23cb49cc386533ff3512a21690cb89190cc Author: 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.txt this is just a test! this is just a test! hahhhh
参考资料:
http://my.oschina.net/u/877348/blog/152660
时间: 2024-10-07 08:27:02