第一次用git 和手冊

一,git clone [email protected]:quark/fouge.git
出現permission denied

解決方式:
1. ssh-keygen -t rsa 會生成兩個文件 id_rsa, id_rsa.pub
2. 把id_rsa.pub裏的東西添加到git account裏的SSH Public Keys。

二,然後輸入passpharse,git clone ....


如果git push出現:
warning: You did not specify any refspecs to push, and the current remote
warning: has not configured any push refspecs. The default action in this
warning: case is to push all matching refspecs, that is, all branches
warning: that exist both locally and remotely will be updated. This may
warning: not necessarily be what you want to happen.
warning:
warning: You can specify what action you want to take in this case, and
warning: avoid seeing this message again, by configuring 'push.default' to:
warning: 'nothing' : Do not push anything
warning: 'matching' : Push all matching branches (default)
warning: 'tracking' : Push the current branch to whatever it is tracking
warning: 'current' : Push the current branch

增加一個配置
git config push.default current

下面文檔來源於:
http://hi.chinaunix.net/?21747227/viewspace-42437

流程:取代碼 → 每次工作前更新代碼到最新版本 → 修改代碼 → 提交代碼到服務器
取代碼及修改全局設置

設置用戶名與郵箱

git config--global user.name"My Name"
git config--global user.email"[email protected]"

從已有的git庫中提取代碼
git clone git@server:app.git

每次更改代碼的操作
更新本地代碼到最新版本(需要merge才能合到本地代碼中)
git fetch

合併更新後的代碼到本地
git merge

更新代碼方式的另一種方法(git pull是git fetch和git merge命令的一個組合)
git pull

修改代碼後,查看已修改的內容
git diff--cached

將新增加文件加入到git中
git add file1

從git中刪除文件

git rm file1
git rm-r dir1

提交修改

git commit-m'this is memo'

如果想省掉提交之前的 git add 命令,可以直接用

git commit-a -m'this is memo'

commit和commit -a的區別, commit -a相當於:

* 第一步:自動地add所有改動的代碼,使得所有的開發代碼都列於index file中

* 第二步:自動地刪除那些在index file中但不在工作樹中的文件

* 第三步:執行commit命令來提交

提交所有修改到遠程服務器,這樣,其它團隊成員才能更新到這些修改

git push

其它常用命令

顯示commit日誌
git log

不僅顯示commit日誌,而且同時顯示每次commit的代碼改變。
git log -p

回滾代碼:

git revert HEAD

你也可以revert更早的commit,例如:

git revert HEAD^

將branch name分支合併到當前分支中。(如果合併發生衝突,需要自己解決衝突)

git merge branchname

解決衝突

當merge命令自身無法解決衝突的時候,它會將工作樹置於一種特殊的狀態,並且給用戶提供衝突信息,以期用戶可以自己解決這些問題。當然在這個時候,未發生衝突的代碼已經被git merge登記在了index file裏了。如果你這個時候使用git diff,顯示出來的只是發生衝突的代碼信息。

在你解決了衝突之前,發生衝突的文件會一直在index file中被標記出來。這個時候,如果你使用git commit提交的話,git會提示:filename.txt needs merge

在發生衝突的時候,如果你使用git status命令,那麼會顯示出發生衝突的具體信息。

在你解決了衝突之後,你可以使用如下步驟來提交:

第一步(如果需要增加文件):

git add file1

第二步:

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