git 基本操作和简单命令

#初始化本地Git存储库

git init

#将所有(文件和目录)添加到Git存储库

git add .

#将文件提交到本地存储库

git commit -m " commit"

#提交更改,-a将提交修改后的文件,但不会自动添加新文件
git commit -a -m "These are new changes"

#显示日志文件

git log

#通过diff命令检查更改 显示未提交文件之间的差异 以及当前分支中的最后一个提交

git diff

#查看存储库的当前状态(包括改变 添加 删除)
git status

# 在当前工作目录的上一层建立一个远端仓库 『remote-repository.git』

git clone --bare . ../remote-repository.git

#检查内容,它与此完全相同。git目录repo01
ls ~/remote-repository.git


-----------------------------------------------------------------------------------------
1.5.2 推送更改到其他的仓库
做一些更改,然后将这些更改从你的第一个仓库推送到一个远端仓库

cd ~/repo01

echo "Hello, hello. Turn your radio on" > test01echo "Bye, bye. Turn your radio off" > test02

git commit -a -m "Some changes"

需要设置

git config --global push.default simple

git push --set-upstream ../remote-repository.git master

git push ../remote-repository.git

----------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------

1.5.3 添加远端仓库

 

除了通过完整的URL来访问Git仓库外,还可以通过git remote add命令为仓库添加一个短名称。当你克隆了一个仓库以后,origin表示所克隆的原始仓库。即使我们从零开始,这个名称也存在。

 

# Add ../remote-repository.git with the name origin

git remote add origin ../remote-repository.git

$ git remote add origin https://gitee.com/wuqingfeng/xxcit.git


#又有些变化

echo "I added a remote repo" > test02

# 提交

git commit -a -m "This is a test for the new remote origin"

# 如果你没有给存储库贴上标签,它将会被推到 origin

git push origin

--------------------------------------------------------------------------------------------

#显示已定义的远程存储库
git remote

----------------------------------------------------------------------------------


1.6.4 推送(push)一个分支到远端仓库

 

默认的,Git只会推送匹配的分支的远端仓库。这意味在使用git push命令默认推送你的分支之前,需要手工的推送一次这个分支。

# 将testing分支推到远程存储库

git push origin testing

 

# 选择testing 分支(branch)

git checkout testing

 

# 改变一下

echo "News for you" > test01

git commit -a -m "new feature in branch"

 

# Push all including branch(包括分支)

git push

通过这种方式,你可以确定哪些分支对于其他仓库是可见的,而哪些只是本地的分支

 


--------------------------------------------------------------------------------

#谁创建了或者是修改了这个文件
git blame filename
    


#以上上个commit信息为起点,创建一条
git checkout -b mybranch
    


#新的分支
master~1
    

可参考

http://www.cnblogs.com/juking/p/5900344.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值