Git Basics

  • git init && git clone
#Initializing a Repository in an Existing Directory
$ git init

#Cloning an Existing Repository
$ git clone https://github.com/libgit2/libgit2

#Cloning an Existing Repository with another name
$ git clone https://github.com/libgit2/libgit2  mylibgit
  • git status
$ git status

#short status
$ git status -s
  • Ignoring Files
$ cat .gitignore

The rules for the patterns you can put in the .gitignore file are as follows:
Blank lines or lines starting with # are ignored.
Standard glob patterns work.
You can start patterns with a forward slash (/) to avoid recursivity.
You can end patterns with a forward slash (/) to specify a directory.
You can negate a pattern by starting it with an exclamation point (!).

# no .a files
*.a

# but do track lib.a, even though you're ignoring .a files above
!lib.a

# only ignore the TODO file in the current directory, not subdir/TODO
/TODO

# ignore all files in the build/ directory
build/

# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt

# ignore all .pdf files in the doc/ directory
doc/**/*.pdf
  • git diff
#see changes not yet staged
$ git diff

#see changes have staged
$ git diff --staged

  • git commit
#commit changes
$ git commit 

#commit with commit message inline
$ git commit -m "commit messages"

#commit to skip the staging area,for the traced files
$ git commit -a -m "commit messages"
  • git rm
#remove a file from Git,also remove it from working directory
$ git rm README.md

#remove a file from Git,keep it in working directory
$ git rm --cached README.md

#You can pass files, directories, and file-glob patterns to the git rm command.
$ git rm log/\*.log
  • git mv
#rename a file
$ git mv file_from file_to

#this is equivalent to running something like this:
$ mv README.md README
$ git rm README.md
$ git add README
  • git log
#view the commit history
$ git log

#-p shows the difference, -2 limits the output to last two entries:
$git log -p -2 

#--stat display what happened,see abbreviated stats for each commit
$ git log --stat

# --pretty,changes the log output to formats other than the default.
$ git log --pretty=oneline

# format, specify you own log output format.
$ git log --pretty=format:"%h - %an, %ar: %s"

# --graph,adds a nice little ASCII graph showing
$ git log --pretty=format:"%h %s" --graph

#limit log output
$ git log --since=2.weeks

#see which commits modifying test files in the Git source code history are merged and were committed by Junio Hamano in the month of October 2008
$ git log --pretty="%h - %s" --author=gitster --since="2008-10-01" \
   --before="2008-11-01" --no-merges -- t/


Option Description
-(n) Show only the last n commits
--since, --after Limit the commits to those made after the specified date.
--until, --before Limit the commits to those made before the specified date.
--author Only show commits in which the author entry matches the specified string.
--committer Only show commits in which the committer entry matches the specified string.
--grep Only show commits with a commit message containing the string
-S Only show commits adding or removing code matching the string
  • git undo
# --amend,amend to the last commit 
$ git commit --amend

#unstaging a staged file
$ git reset HEAD <file>....

#unmodify a modified file
$ git checkout -- <file>...
  • git remote
#list remotes
$ git remote

$ git remote -v

#add remote repository
$ git remote add pb https://github.com/paulboone/ticgit

#fetch from remote
$ git fetch pb

#push to remote
$ git push origin master

#inspect a remote
$ git remote show origin

#rename and remove
$ git remote rename pb paul

$ git remote rm paul
  • git tag
#list your tags
$ git tag

#search tags
$ git tag -l "v1.8.5*"

#create a tag
$ git tag -a v1.4 -m "my version 1.4"

#show a tag
$ git show v1.4

#push tag
$ git push origin [tagname]

#push all tags
$ git push origin --tags

#checkout tags
$ git checkout -b [branchname] [tagname]
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末轴或,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子条篷,更是在濱河造成了極大的恐慌宋欺,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,496評(píng)論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件雪营,死亡現(xiàn)場(chǎng)離奇詭異弓千,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)献起,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,407評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門(mén)洋访,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)镣陕,“玉大人,你說(shuō)我怎么就攤上這事姻政〈粢郑” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 162,632評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵汁展,是天一觀的道長(zhǎng)鹊碍。 經(jīng)常有香客問(wèn)我,道長(zhǎng)食绿,這世上最難降的妖魔是什么侈咕? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,180評(píng)論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮器紧,結(jié)果婚禮上耀销,老公的妹妹穿的比我還像新娘。我一直安慰自己铲汪,他們只是感情好树姨,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,198評(píng)論 6 388
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著桥状,像睡著了一般帽揪。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上辅斟,一...
    開(kāi)封第一講書(shū)人閱讀 51,165評(píng)論 1 299
  • 那天转晰,我揣著相機(jī)與錄音,去河邊找鬼士飒。 笑死查邢,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的酵幕。 我是一名探鬼主播扰藕,決...
    沈念sama閱讀 40,052評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼芳撒!你這毒婦竟也來(lái)了邓深?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 38,910評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤笔刹,失蹤者是張志新(化名)和其女友劉穎芥备,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體舌菜,經(jīng)...
    沈念sama閱讀 45,324評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡萌壳,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,542評(píng)論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片袱瓮。...
    茶點(diǎn)故事閱讀 39,711評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡缤骨,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出尺借,到底是詐尸還是另有隱情荷憋,我是刑警寧澤,帶...
    沈念sama閱讀 35,424評(píng)論 5 343
  • 正文 年R本政府宣布褐望,位于F島的核電站,受9級(jí)特大地震影響串前,放射性物質(zhì)發(fā)生泄漏瘫里。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,017評(píng)論 3 326
  • 文/蒙蒙 一荡碾、第九天 我趴在偏房一處隱蔽的房頂上張望谨读。 院中可真熱鬧,春花似錦坛吁、人聲如沸劳殖。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,668評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)哆姻。三九已至,卻和暖如春玫膀,著一層夾襖步出監(jiān)牢的瞬間矛缨,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,823評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工帖旨, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留箕昭,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,722評(píng)論 2 368
  • 正文 我出身青樓解阅,卻偏偏與公主長(zhǎng)得像落竹,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子货抄,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,611評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容

  • 輸入 y 述召,創(chuàng)建 git_hug 目錄No githug directory found, do you wish...
    風(fēng)花花閱讀 1,927評(píng)論 0 4
  • 1. GIT命令 git init在本地新建一個(gè)repo,進(jìn)入一個(gè)項(xiàng)目目錄蟹地,執(zhí)行g(shù)it init桨武,會(huì)初始化一個(gè)re...
    江邊一蓑煙閱讀 798評(píng)論 0 0
  • 查看、添加锈津、提交呀酸、刪除、找回琼梆,重置修改文件 git help # 顯示command的help git sho...
    Swiftor閱讀 2,111評(píng)論 0 2
  • UG培訓(xùn)第三十六天 第四道考核的分析建模
    陽(yáng)光155閱讀 101評(píng)論 0 0
  • 邏輯回歸:假設(shè)數(shù)據(jù)服從伯努利分布的線性分類(lèi)模型性誉。 邏輯回歸損失函數(shù)推導(dǎo) 一窿吩、邏輯回歸模型 邏輯回歸模型可以看作是由...
    菜鳥(niǎo)瞎編閱讀 660評(píng)論 0 0