windows GIT使用笔记

在Windows上应用git,一般采用工具msysgit,下载地址为:
 
 
 
假设创建的主版本库位置在 D:\SourceCODE\GITMainLib
 
在文件夹GITMainLib中右键菜单进入GitBash
 
创建空的主版本库
git init
 
生成第一个你文件
echo Version1_A > a.txt
 
查看当前状态
git status
 
本地添加文件a.txt
git add a.txt
 
生成文件1.txt,2.txt
touch 1.txt
touch 2.txt
 
本地添加
git add .
 
本地提交a.txt
git commit a.txt
 
本地提交所有其他文件
git commit -m "add other files"
 
查看操作日志
git log
 
移除1.txt 2.txt
git rm 1.txt
git rm 2.txt
 
查看当前状态
git status
 
提交删除操作
git commit -m "remove 1.txt 2.txt"
 
查看操作日志
git log
 
查看当前branch
git branch
 
创建新的branch分支:branch-test
git branch branch-test
 
切换到分支:branch-test
git checkout branch-test
 
查看当前branch,可以看到当前分支已经为branch-test了
git branch
 
生成bransh-test.txt文件
echo "branch-test text" > branch-test.txt
 
添加,提交到branch-test分支
git add .
git commit -m "add branch-test.txt on branch-test"
 
切换到master分支
git checkout master
 
生成b.txt,添加,提交到master分支
touch b.txt
git add .
git commit -m "add b.txt on master branch"
 
合并branch-test分支到master分支
git merge master branch-test
 
删除分支:branch-test,注意删除前一定要切换的其他分支
git checkout master
git branch -D branch-test
 
通过主版本库得到第二个版本库
假设创建的主版本库位置在 D:\SourceCODE\GITLibClone
在文件夹GITLibClone中右键菜单进入GitBash
 
得到版本库
git clone ./GITMainLib
 
进入第二个版本库
cd GITMainLib/
 
在第二个版本库的master分支上创建文件,添加,提交
echo "i'm created by the second library of version" > 2v.txt
git add .
git commit -m "created by cloned library"
 
 
在主版本库的里添加文件,提交
touch file_after_clone.txt
git add .
git commit -m "add after clone"
 
在第二个版本库里得到主版本库的更新,成功后可以看到目录中出现了文件file_after_clone.txt
git pull
 
第二个版本库文件更新到主版本库的fromv2分支
git push ../../GITMainLib master:fromv2
 
 
主版本库合并第二个版本库提交的分支fromv2
git merge master fromv2
 
主版本库删除分支fromv2
git branch -D fromv2
 
第二个版本库添加文件,提交
touch wntbymfetch.txt
git add .
git commit -m  "want the main library to fetch"
 
 
主版本库更新第二个版本库的修改
git pull ../GITLibClone/GITMainLib
 
第二个版本库修改文件a.txt
echo "Modifed by second library" >> a.txt
git commit -a -m "Modified by the second library"
 
主版本库修改文件a.txt
echo "Modifed by  the main library" >> a.txt
git commit -a -m "Mofied by the main library"
 
主版本库从第二个版本库pull方式更新
git pull ../GITLibClone/GITMainLib
显示更新失败
Auto-merging a.txt
CONFLICT (content): Merge conflict in a.txt
Automatic merge failed; fix conflicts and then commit the result.
 
冲突了吧,这时候可以调用
git mergetool
来调用GUI的merge工具
merge成功后调用
git -commit -m "After merged"
来提交。
 
关于
关于 git commit -a 参看下面文章
git commit   -m  "提交的描述信息"
如果我们这里不用 -m参数的话,git将调到一个文本编译器(通常是vim)来让你输入提交的描述信息
可能一天下来,你对工作树中的许多文档都进行了更新(文档添加、修改、删除),但是我忘记了它们的名字,此时若将所做的全部更新添加到索引中,比较轻省的做法就是:
git commit  -a  -m  "提交的描述信息"
git commit  命令的 -a  选项可只将所有被修改或者已删除的 且已经被git管理 的文档提交倒仓库中如果只是修改或者删除了已被Git 管理的文档,是没必要使用 git add  命令的。
git add  .命令除了能够判断出当前目录(包括其子目录) 所有被修改或者已删除的文档,还能判断 用户所添加的新文档 ,并将其信息追加到索引中。
另外 ,要注意的问题是,Git 不会主动记录你对文档进行的更新,除非你对它发号施令(比如通过git add命令
 
 
 

 http://wuzongbin2008.blog.163.com/blog/static/2146873320110613821860/

reset命令有3种方式:

  1. git reset –mixed:此为默认方式,不带任何参数的git reset,即时这种方式,它回退到某个版本,只保留源码,回退commit和index信息
  2. git reset –soft:回退到某个版本,只回退了commit的信息,不会恢复到index file一级。如果还要提交,直接commit即可
  3. git reset –hard:彻底回退到某个版本,本地的源码也会变为上一个版本的内容

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值