【Git入门之四】操作项目 - JackyStudio - 博客频道 - CSDN.NET
1.查看操作日记
《git log》用于查看操作日记详情。因为Git是分布式的,采用SHA1这样的版本号可有效的防止版本冲突。
[cpp]?view
plaincopy
?
- #查看操作日记,底下那串长长的数据就是SHA1?ID,表示当前版本号??
- $Snbsp;git?log??
- commit?aea0365712908805bc28540b4db9fd2f15360a8b??
- Author:?Jacky?<[email protected]>??
- Date:???Fri?Sep?27?15:15:48?2013?+0800??
- ??
- ????init?AddFiles??
2.修改项目内容
[cpp]?view
plaincopy
?
- #修改JackyData01内容??
- $Snbsp;echo?"HelloGit"?>?JackyData01??
?
3.查看当前状态
[cpp]?view
plaincopy
?
- #查看版本库状态,可以看到红色的JackyData01被修改过??
- $Snbsp;git?status??
- #?On?branch?master??
- #?Changes?not?staged?for?commit:??
- #???(use?"git?add?<file>..."?to?update?what?will?be?committed)??
- #???(use?"git?checkout?--?<file>..."?to?discard?changes?in?working?directory)??
- #??
- #???????modified:???Jackydata01??
- #??
- no?changes?added?to?commit?(use?"git?add"?and/or?"git?commit?-a")??
4.提交修改
这里使用《git commit -a -m “提交信息”》可以省掉先放到暂存区的操作,直接提交。
[cpp]?view
plaincopy
?
- #直接提交修改??
- $Snbsp;git?commit?-a?-m?"modify?JackyData01"??
- [master?cba8800]?modify?JackyData01??
- ?1?file?changed,?1?insertion(+),?2?deletions(-)??
5.查看操作日记
还用《git log》,不过这次我们给它添加一个参数,这样浏览起来会方便很多。
[cpp]?view
plaincopy
?
- #单行显示,只显示版本号和备注??
- $Snbsp;git?log?--pretty=oneline??
- cba8800f2daaf4075a506b6d763798ea15ba11cc?modify?JackyData01??
- aea0365712908805bc28540b4db9fd2f15360a8b?init?AddFiles??
6.查看不同
《git diff》用于比较上一次提交和当前版本的差异。
[cpp]?view
plaincopy
?
- #修改JackyData02的内容为HelloGit??
- $Snbsp;echo?"HelloGit"?>?JackyData02??
- ??
- #使用Git?diff查看差异,可以看到HelloJacky被删除了,而HelloGit被添加了??
- $Snbsp;git?diff??
- diff?--git?a/JackyData02?b/JackyData02??
- index?85d5336..1da19b8?100644??
- ---?a/JackyData02??
- +++?b/JackyData02??
- @@[email protected]@??
- -HellloJacky??
- +HelloGit??
7.提交修改并打开Git GUI界面
《gitk --all》用于打开Git的GUI界面。
[cpp]?view
plaincopy
?
- #提交修改??
- $Snbsp;git?add?.?&&?git?commit?-m?"modify?JackyData02"??
- [master?a5f6601]?modify?JackyData02??
- ?1?file?changed,?1?insertion(+),?1?deletion(-)??
- ??
- #打开GUI界面??
- $Snbsp;gitk?--all??
?
8.修改提交信息
使用《git commit --amend》可以修改上次提交的信息。
?
[cpp]?view
plaincopy
?
- #重新修改上次提交信息??
- $Snbsp;git?commit?--amend?-m?"amend?modify?JackyData02"??
- [master?a25c588]?amend?modify?JackyData02??
- ?1?file?changed,?1?insertion(+),?1?deletion(-)??
- ??
- #最后一次的提交信息被修改??
- $Snbsp;git?log?--pretty=oneline??
- a25c58804cb3f4045564fc0ec6a4e6eb4dae7072?amend?modify?JackyData02??
- cba8800f2daaf4075a506b6d763798ea15ba11cc?modify?JackyData01??
- aea0365712908805bc28540b4db9fd2f15360a8b?init?AddFiles??
9.删除项目内容
删除了某一项版本控制下的内容,使用《git add .》无法在索引中删除该文件。
?
[cpp]?view
plaincopy?
- #移除JackyData03文件??
- $Snbsp;rm?JackyData03??
- ??
- #使用git?add?.?提示警告,同时调用git?status,发现并没有正常提交??
- $Snbsp;git?add?.?&&?git?commit?-m?"remove?JackyData03"??
- warning:?You?ran?‘git?add‘?with?neither?‘-A?(--all)‘?or?‘--ignore-removal‘,??
- whose?behaviour?will?change?in?Git?2.0?with?respect?to?paths?you?removed.??
- Paths?like?‘JackyData03‘?that?are??
- removed?from?your?working?tree?are?ignored?with?this?version?of?Git.??
- ??
- *?‘git?add?--ignore-removal?<pathspec>‘,?which?is?the?current?default,??
- ??ignores?paths?you?removed?from?your?working?tree.??
- ??
- *?‘git?add?--all?<pathspec>‘?will?let?you?also?record?the?removals.??
- ??
- Run?‘git?status‘?to?check?the?paths?you?removed?from?your?working?tree.??
- ??
- #?On?branch?master??
- #?Changes?not?staged?for?commit:??
- #???(use?"git?add/rm?<file>..."?to?update?what?will?be?committed)??
- #???(use?"git?checkout?--?<file>..."?to?discard?changes?in?working?directory)??
- #??
- #???????deleted:????JackyData03??
- #??
- no?changes?added?to?commit?(use?"git?add"?and/or?"git?commit?-a")??
需使用《git commit -a -m “提交信息”》或者《git add -A . git commit -m “提交信息”》才能达到删除的目的。
?
[cpp]?view
plaincopy?
- #使用git?commit?-a?-m提交删除??
- $Snbsp;git?commit?-a?-m?"remove?JackyData03"??
- [master?c5c83cf]?remove?JackyData03??
- ?1?file?changed,?1?deletion(-)??
- ?delete?mode?100644?JackyData03
?
时间: 2024-10-21 21:43:46