git命令列基本用法

2021-07-10 06:21:58 字數 2530 閱讀 6512

如果對git命令列不熟悉的話,用git圖形介面工具,就比較合適了。建議使用tortoisegit 或sourectree這樣的工具,命令列從學習到靈活掌握的時間成本比較高的。

1,新增

# git clone [email protected]:develop/test.git

# cd test

# touch test.txt //測試檔案

# git add test.txt //git新增檔案

# git commit -m 'test' //新增到本地版本庫

# git push //push到遠端

如果push報錯,perhaps you should specify a branch such as 'master'

解決辦法:

# git push origin master //只要這樣操作一次,以後就可以用git push

新增檔案和新增目錄,操作是一樣的。

2,修改檔案

方法一# echo "11111111111" > test.txt

# git add test.txt && git commit -m 'test2'

# git push

方法二# echo "abc" > test.txt

# git commit -am "test3" //所有修改都會提交

# git push

如果有多個檔案,只想提交其中的乙個或者多個,怎麼辦呢

# git commit -a //該命令出現以下內容

# please enter the commit message for your changes. lines starting

# with '#' will be ignored, and an emptyempty message aborts the commit.

# on branch master

# changes to be committed:

# (use "git reset head ..." to unstage)

## modified: ab

# modified: test.txt //如果只想提交test.txt,只要把該行前的#去掉,儲存退出就行了

# git push //退出後,在執行push

3,刪除

# git rm ab //如果刪除目錄的話,加上-r

# git commit -am "del"

# git push

4,解決衝突

# git push //push不上去

address 192.168.10.202 maps to unassigned.psychz.net, but this does not map back to the address - possible break-in attempt!

to [email protected]:develop/test.git

! [rejected] master -> master (non-fast-forward)

error: failed to push some refs to '192.168.10.202:develop/test.git'

to prevent you from losing history, non-fast-forward updates were rejected

merge the remote changes before pushing again. see the 'note about

fast-forwards' section of 'git push --help' for details.

# git pull //更新**,提示衝突

address 192.168.10.202 maps to unassigned.psychz.net, but this does not map back to the address - possible break-in attempt!

remote: counting objects: 5, done.

remote: compressing objects: 100% (2/2), done.

remote: total 3 (delta 0), reused 0 (delta 0)

unpacking objects: 100% (3/3), done.

from 192.168.10.202:develop/test

367dad3..5e5640b master -> origin/master

auto-merging test.txt

conflict (content): merge conflict in test.txt

automatic merge failed; fix conflicts and then commit the result.

# vim test.txt //修改衝突檔案,並儲存

# git commit -am "remove conflict" //重新提交到本地版本庫

# git push //同步到遠端

Git命令列基本操作

網上有很多git安裝教程,如果需要圖形介面,windows下建議使用tortoisegit,linux建議使用git gui或者gitk。git config可以配置git的引數,可以使用git config list檢視已經配置的git引數。其中有三個級別的儲存位置,system global l...

Scrapy命令列基本用法

1.建立乙個新專案 scrapy startproject myproject 2.在新專案中建立乙個新的spider檔案 scrapy genspider mydomain mydomain.com mydomain為spider檔名,mydomain.com為爬取 網域名稱 3.全域性命令 st...

scrapy 命令列基本用法

1.建立乙個新專案 scrapy startproject myproject2.在新專案中建立乙個新的spider檔案 scrapy genspider mydomain mydomain.commydomain為spider檔名,mydomain.com為爬取 網域名稱 3.全域性命令 star...