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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章