Git In Five Minutes (zz)
  ppGGiSfbs6Lj 2023年11月02日 75 0


//z 2014-08-31 07:44:48 IS2120@BYH T3568670012.K.F2983803428[T7,L125,R6,V74]
Git的基本命令:git pull:从其他的版本库(既可以是远程的也可以是本地的)将代码更新到本地,例如:'git pull origin master'就是将origin这个版本库的代码更新到本地的master主枝,该功能类似于SVN的updategit add:是将当前更改或者新增的文件加入到Git的索引中,加入到Git的索引中就表示记入了版本历史中,这也是提交之前所需要执行的一步,例如'git add app/model/user.rb'就会增加app/model/user.rb文件到Git的索引中,该功能类似于SVN的addgit rm:从当前的工作空间中和索引中删除文件,例如'git rm app/model/user.rb',该功能类似于SVN的rm、delgit commit:提交当前工作空间的修改内容,类似于SVN的commit命令,例如'git commit -m story #3, add user model',提交的时候必须用-m来输入一条提交信息,该功能类似于SVN的commitgit push:将本地commit的代码更新到远程版本库中,例如'git push origin'就会将本地的代码更新到名为orgin的远程版本库中git log:查看历史日志,该功能类似于SVN的loggit revert:还原一个版本的修改,必须提供一个具体的Git版本号,例如'git revert bbaf6fb5060b4875b18ff9ff637ce118256d6f20',Git的版本号都是生成的一个哈希值//z 2014-04-25 14:38:50 L.250'33670 BG57IV3@XCL T1700535830.K.F253293061 [T306,L4288,R199,V5556]
git 放弃本地修改 强制更新
git fetch --all
git reset --hard origin/master
git fetch 只是下载远程的库的内容,不做任何的合并 git reset 把HEAD指向刚刚下载的最新的版本

本文将对Git 命令,做一下全面而系统的简短总结,整理成简洁、明了的图表结构,方便查询

一、 Git 常用命令速查

git branch 查看本地所有分支
git status 查看当前状态 
git commit 提交 
git branch -a 查看所有的分支
git branch -r 查看远程所有分支
git commit -am "init" 提交并且加注释 
git remote add origin git@192.168.1.119:ndshow
git push origin master 将文件给推到服务器上 
git remote show origin 显示远程库origin里的资源 
git push origin master:develop
git push origin master:hb-dev 将本地库与服务器上的库进行关联 
git checkout --track origin/dev 切换到远程dev分支
git branch -D master develop 删除本地库develop
git checkout -b dev 建立一个新的本地分支dev
git merge origin/dev 将分支dev与当前分支进行合并
git checkout dev 切换到本地dev分支
git remote show 查看远程库
git add .
git rm 文件名(包括路径) 从git中删除指定文件
git clone git://github.com/schacon/grit.git 从服务器上将代码给拉下来
git config --list 看所有用户
git ls-files 看已经被提交的
git rm [file name] 删除一个文件
git commit -a 提交当前repos的所有的改变
git add [file name] 添加一个文件到git index
git commit -v 当你用-v参数的时候可以看commit的差异
git commit -m "This is the message describing the commit" 添加commit信息
git commit -a -a是代表add,把所有的change加到git index里然后再commit
git commit -a -v 一般提交命令
git log 看你commit的日志
git diff 查看尚未暂存的更新
git rm a.a 移除文件(从暂存区和工作区中删除)
git rm --cached a.a 移除文件(只从暂存区中删除)
git commit -m "remove" 移除文件(从Git中删除)
git rm -f a.a 强行移除修改后文件(从暂存区和工作区中删除)
git diff --cached 或 $ git diff --staged 查看尚未提交的更新
git stash push 将文件给push到一个临时空间中
git stash pop 将文件从临时空间pop下来
---------------------------------------------------------
git remote add origin git@github.com:username/Hello-World.git
git push origin master 将本地项目给提交到服务器中
-----------------------------------------------------------
git pull 本地与服务器端同步
-----------------------------------------------------------------
git push (远程仓库名) (分支名) 将本地分支推送到服务器上去。
git push origin serverfix:awesomebranch
------------------------------------------------------------------
git fetch 相当于是从远程获取最新版本到本地,不会自动merge
git commit -a -m "log_message" (-a是提交所有改动,-m是加入log信息) 本地修改同步至服务器端 :
git branch branch_0.1 master 从主分支master创建branch_0.1分支
git branch -m branch_0.1 branch_1.0 将branch_0.1重命名为branch_1.0
git checkout branch_1.0/master 切换到branch_1.0/master分支
du -hs

git branch 删除远程branch

git push origin :branch_remote_name

git branch -r -d branch_remote_name

-----------------------------------------------------------

初始化版本库,并提交到远程服务器端
mkdir WebApp
cd WebApp
git init 本地初始化
touch README
git add README 添加文件
git commit -m 'first commit'
git remote add origin git@github.com:daixu/WebApp.git 增加一个远程服务器端

上面的命令会增加URL地址为'git@github.com:daixu/WebApp.git',名称为origin的远程服务器库,以后提交代码的时候只需要使用 origin别名即可

二、 Git 命令速查表


1、常用的Git命令

命令

简要说明

git add

添加至暂存区

git add–interactive

交互式添加

git apply

应用补丁

git am

应用邮件格式补丁

git annotate

同义词,等同于 git blame

git archive

文件归档打包

git bisect

二分查找

git blame

文件逐行追溯

git branch

分支管理

git cat-file

版本库对象研究工具

git checkout

检出到工作区、切换或创建分支

git cherry-pick

提交拣选

git citool

图形化提交,相当于 git gui 命令

git clean

清除工作区未跟踪文件

git clone

克隆版本库

git commit

提交

git config

查询和修改配置

git describe

通过里程碑直观地显示提交ID

git diff

差异比较

git difftool

调用图形化差异比较工具

git fetch

获取远程版本库的提交

git format-patch

创建邮件格式的补丁文件。参见 git am 命令

git grep

文件内容搜索定位工具

git gui

基于Tcl/Tk的图形化工具,侧重提交等操作

git help

帮助

git init

版本库初始化

git init-db*

同义词,等同于 git init

git log

显示提交日志

git merge

分支合并

git mergetool

图形化冲突解决

git mv

重命名

git pull

拉回远程版本库的提交

git push

推送至远程版本库

git rebase

分支变基

git rebase–interactive

交互式分支变基

git reflog

分支等引用变更记录管理

git remote

远程版本库管理

git repo-config*

同义词,等同于 git config

git reset

重置改变分支“游标”指向

git rev-parse

将各种引用表示法转换为哈希值等

git revert

反转提交

git rm

删除文件

git show

显示各种类型的对象

git stage*

同义词,等同于 git add

git stash

保存和恢复进度

git status

显示工作区文件状态

git tag

里程碑管理


2、对象库操作相关命令

命令

简要说明

git commit-tree

从树对象创建提交

git hash-object

从标准输入或文件计算哈希值或创建对象

git ls-files

显示工作区和暂存区文件

git ls-tree

显示树对象包含的文件

git mktag

读取标准输入创建一个里程碑对象

git mktree

读取标准输入创建一个树对象

git read-tree

读取树对象到暂存区

git update-index

工作区内容注册到暂存区及暂存区管理

git unpack-file

创建临时文件包含指定 blob 的内容

git write-tree

从暂存区创建一个树对象


3、引用操作相关命令

命令

简要说明

git check-ref-format

检查引用名称是否符合规范

git for-each-ref

引用迭代器,用于shell编程

git ls-remote

显示远程版本库的引用

git name-rev

将提交ID显示为友好名称

git peek-remote*

过时命令,请使用 git ls-remote

git rev-list

显示版本范围

git show-branch

显示分支列表及拓扑关系

git show-ref

显示本地引用

git symbolic-ref

显示或者设置符号引用

git update-ref

更新引用的指向

git verify-tag

校验 GPG 签名的Tag


4、版本库管理相关命令

命令

简要说明

git count-objects

显示松散对象的数量和磁盘占用

git filter-branch

版本库重构

git fsck

对象库完整性检查

git fsck-objects*

同义词,等同于 git fsck

git gc

版本库存储优化

git index-pack

从打包文件创建对应的索引文件

git lost-found*

过时,请使用 git fsck –lost-found 命令

git pack-objects

从标准输入读入对象ID,打包到文件

git pack-redundant

查找多余的 pack 文件

git pack-refs

将引用打包到 .git/packed-refs 文件中

git prune

从对象库删除过期对象

git prune-packed

将已经打包的松散对象删除

git relink

为本地版本库中相同的对象建立硬连接

git repack

将版本库未打包的松散对象打包

git show-index

读取包的索引文件,显示打包文件中的内容

git unpack-objects

从打包文件释放文件

git verify-pack

校验对象库打包文件


5、数据传输相关命令

命令

简要说明

git fetch-pack

执行 git fetch 或 git pull 命令时在本地执行此命令,用于从其他版本库获取缺失的对象

git receive-pack

执行 git push 命令时在远程执行的命令,用于接受推送的数据

git send-pack

执行 git push 命令时在本地执行的命令,用于向其他版本库推送数据

git upload-archive

执行 git archive –remote 命令基于远程版本库创建归档时,远程版本库执行此命令传送归档

git upload-pack

执行 git fetch 或 git pull 命令时在远程执行此命令,将对象打包、上传


6、邮件相关命令

命令

简要说明

git imap-send

将补丁通过 IMAP 发送

git mailinfo

从邮件导出提交说明和补丁

git mailsplit

将 mbox 或 Maildir 格式邮箱中邮件逐一提取为文件

git request-pull

创建包含提交间差异和执行PULL操作地址的信息

git send-email

发送邮件


7、协议相关命令

命令

简要说明

git daemon

实现Git协议

git http-backend

实现HTTP协议的CGI程序,支持智能HTTP协议

git instaweb

即时启动浏览器通过 gitweb 浏览当前版本库

git shell

受限制的shell,提供仅执行Git命令的SSH访问

git update-server-info

更新哑协议需要的辅助文件

git http-fetch

通过HTTP协议获取版本库

git http-push

通过HTTP/DAV协议推送

git remote-ext

由Git命令调用,通过外部命令提供扩展协议支持

git remote-fd

由Git命令调用,使用文件描述符作为协议接口

git remote-ftp

由Git命令调用,提供对FTP协议的支持

git remote-ftps

由Git命令调用,提供对FTPS协议的支持

git remote-http

由Git命令调用,提供对HTTP协议的支持

git remote-https

由Git命令调用,提供对HTTPS协议的支持

git remote-testgit

协议扩展示例脚本


8、版本库转换和交互相关命令

命令

简要说明

git archimport

导入Arch版本库到Git

git bundle

提交打包和解包,以便在不同版本库间传递

git cvsexportcommit

将Git的一个提交作为一个CVS检出

git cvsimport

导入CVS版本库到Git。或者使用 cvs2git

git cvsserver

Git的CVS协议模拟器,可供CVS命令访问Git版本库

git fast-export

将提交导出为 git-fast-import 格式

git fast-import

其他版本库迁移至Git的通用工具

git svn

Git 作为前端操作 Subversion


9、合并相关的辅助命令

命令

简要说明

git merge-base

供其他脚本调用,找到两个或多个提交最近的共同祖先

git merge-file

针对文件的两个不同版本执行三向文件合并

git merge-index

对index中的冲突文件调用指定的冲突解决工具

git merge-octopus

合并两个以上分支。参见 git merge 的octopus合并策略

git merge-one-file

由 git merge-index 调用的标准辅助程序

git merge-ours

合并使用本地版本,抛弃他人版本。参见 git merge 的ours合并策略

git merge-recursive

针对两个分支的三向合并。参见 git merge 的recursive合并策略

git merge-resolve

针对两个分支的三向合并。参见 git merge 的resolve合并策略

git merge-subtree

子树合并。参见 git merge 的 subtree 合并策略

git merge-tree

显式三向合并结果,不改变暂存区

git fmt-merge-msg

供执行合并操作的脚本调用,用于创建一个合并提交说明

git rerere

重用所记录的冲突解决方案


10、 杂项

命令

简要说明

git bisect–helper

由 git bisect 命令调用,确认二分查找进度

git check-attr

显示某个文件是否设置了某个属性

git checkout-index

从暂存区拷贝文件至工作区

git cherry

查找没有合并到上游的提交

git diff-files

比较暂存区和工作区,相当于 git diff –raw

git diff-index

比较暂存区和版本库,相当于 git diff –cached –raw

git diff-tree

比较两个树对象,相当于 git diff –raw A B

git difftool–helper

由 git difftool 命令调用,默认要使用的差异比较工具

git get-tar-commit-id

从 git archive 创建的 tar 包中提取提交ID

git gui–askpass

命令 git gui 的获取用户口令输入界面

git notes

提交评论管理

git patch-id

补丁过滤行号和空白字符后生成补丁唯一ID

git quiltimport

将Quilt补丁列表应用到当前分支

git replace

提交替换

git shortlog

对 git log 的汇总输出,适合于产品发布说明

git stripspace

删除空行,供其他脚本调用

git submodule

子模组管理

git tar-tree

过时命令,请使用 git archive

git var

显示 Git 环境变量

git web–browse

启动浏览器以查看目录或文件

git whatchanged

显示提交历史及每次提交的改动

git-mergetool–lib

包含于其他脚本中,提供合并/差异比较工具的选择和执行

git-parse-remote

包含于其他脚本中,提供操作远程版本库的函数

git-sh-setup

包含于其他脚本中,提供 shell 编程的函数库



Git In Five Minutes

//z 2012-5-15 9:31:51 AM IS2120
Many people consider git to be too confusing or complex to be a choice for version control. Yet Git considers to grow in adoption, and many interesting things have grown up around it. This document is geared for someone wanted to get started with Git, often coming from a Subversion background. For most basic needs this document will cover 70 to 90 percent of your use.

Getting Started

To use Git you will have to setup a repository. You can take an existing directory to make a Git repository, or create an empty directory.

To make your current directory a Git repository we simply run init.

git init

To make a new directory that is a Git repository we just specify a directory.

git init newrepo

From here on out we'll assume that you are in the root of the Git repository unless otherwise noted.

Adding New Files

So we have a repository, but nothing in it. You can add files with the add command.

git add filename

To add everything in your directory try git add ..

Committing a Version (//z 2012-5-15 9:31:51 AM IS2120@

Now that we've added these files, we want them to actually be stored in the Git repository. We do this by committing them to the repository.

git commit -m "Adding files"

If you leave off the -m you will be put into an editor to write the message yourself.

Editing Files

When you've made changes to some files, you can run git status to see what will happen on commit. You'll notice a list of modified files, and a message:

no changes added to commit (use "git add" and/or "git commit -a")

So running git commit will do nothing unless you explicitly add files to the commit withgit add. If you're looking for the commit command to automatically commit local modifications we use the-a flag.

git commit -a -m "Changed some files"

Or if you'd like to have only certain files, but still not run git add we pass specific files.

git commit -m "change some files" file1 file2

Do note that -a will not cause new files to be committed, only modified.

Publishing Your Repository

To put your repository on a server we'll start by making a "bare" repository, and upload it to a server.

cd /tmp
git clone --bare ~/your/repo/path project.git
scp -r project.git ssh://example.com/~/www/

Now if we have a couple of commits and want to push it up to that location:

git push ssh://example.com/~/www/project.git

If you dislike typing the URI each time we can take advantage that a cloned project remembers where it came from.

cd ..
git clone ssh://example.com/~/www/project.git project

Now git push will push to the URI it was cloned from. You can do this manually by editing.git/config in your repository.

Get Upstream Changes

//z 2012-5-15 9:31:51 AM IS2120@
If you're already setup for push as above:

git pull

Will bring changes down and merge them in. To pull from a non-default location just specify the URI.

git pull http://git.example.com/project.git

More Than Five Minutes

Commits

You'll have noticed that Git thinks in "commits." These are uniquely identified by a hash. You can see the history and the hashes withgit log. Each commit involves modifications, new files, and files being removed.add will put a file in a commit. git reset HEAD will remove everything from the planned commit, but not change files.

Remove

If you want to remove a file from the repository, removing it from future commits we userm.

git rm file

Branching and Merging

Branches are done locally and are fast. To create a new branch we use the branch command.

git branch test

the branch command does not move us into the branch, just create one. So we use thecheckout command to change branches.

git checkout test

The first branch, or main branch, is called "master."

git checkout master

While in your branch you can commit changes that will not be reflected in the master branch. When you're done, or want to push changes to master, switch back to master and usemerge.

git checkout master
git merge test

And if you're done with the branch you can delete with the branch command and pass the-d flag.

git branch -d test

Traveling Through Time

//z 2012-5-15 9:31:51 AM IS2120@
You can quickly very previous states of the repository using the checkout command again.

git checkout HASH

Uncommited changes will travel with you. Return to the preset with git checkout master as with normal branches. If you commit while in the past a branch is automatically created and your changes will have to be merged forward.

Sweeping Changes Under the Rug for Later

When moving between branches your local changes move with you. Sometimes you want to switch branches but not commit or take those changes with you. The Git commandstash lets you put changes into a safe store.

git stash

You can retreive by passing an arguement of apply or pop.

git stash apply

The difference between apple and pop is simple. apply will take a stash state and apply it, but preserve that state in the stash.pop will take the stash state, apply it, and remove it from the stash.git stash clear empties the contents of the stash.

//z 2012-07-07 20:10:37 PM IS2120@.T1552550216[T8,L74,R3,V53]
First you need to add the main repository to your remote references (this only needs to be done once):

git remote add elan git://github.com/elan/plex.git

After that, you can pull the latest updates:

git checkout gordon
git pull elan v0.5

If any merge conflicts happen, you'll need to manually resolve them. You can use:

git mergetool

to start Apple's diff tool for each file with conflicts.


方式一
1. 查看远程仓库

$ git remote -v
eoecn   https://github.com/eoecn/android-app.git (fetch)
eoecn   https://github.com/eoecn/android-app.git (push)
origin  https://github.com/com360/android-app.git (fetch)
origin  https://github.com/com360/android-app.git (push)
su@SUCHANGLI /e/eoe_client/android-app (master)

从上面的结果可以看出,远程仓库有两个,一个是eoecn,一个是origin
2 ,从远程获取最新版本到本地

$ git fetch origin master
From https://github.com/com360/android-app
 * branch            master     -> FETCH_HEAD
su@SUCHANGLI /e/eoe_client/android-app (master)

$ git fetch origin master 这句的意思是:从远程的origin仓库的master分支下载代码到本地的origin master
3. 比较本地的仓库和远程参考的区别

$ git log -p master.. origin/master
su@SUCHANGLI /e/eoe_client/android-app (master)

因为我的本地仓库和远程仓库代码相同所以没有其他任何信息
4. 把远程下载下来的代码合并到本地仓库,远程的和本地的合并

$ git merge origin/master
Already up-to-date.
su@SUCHANGLI /e/eoe_client/android-app (master)

我的本地参考代码和远程代码相同,所以是Already up-to-date

以上的方式有点不好理解,大家可以使用下面的方式,并且很安全
方式二
1.查看远程分支,和上面的第一步相同
2. 从远程获取最新版本到本地

$ git fetch origin master:temp
From https://github.com/com360/android-app
 * [new branch]      master     -> temp
su@SUCHANGLI /e/eoe_client/android-app (master)

git fetch origin master:temp 这句命令的意思是:从远程的origin仓库的master分支下载到本地并新建一个分支temp

  1. 比较本地的仓库和远程参考的区别
$ git diff temp
su@SUCHANGLI /e/eoe_client/android-app (master)

命令的意思是:比较master分支和temp分支的不同
由于我的没有区别就没有显示其他信息
4. 合并temp分支到master分支

$ git merge temp
Already up-to-date.
su@SUCHANGLI /e/eoe_client/android-app (master)

由于没有区别,所以显示Already up-to-date.
合并的时候可能会出现冲突,有时间了再把如何处理冲突写一篇博客补充上。
5.如果不想要temp分支了,可以删除此分支

$ git branch -d temp
Deleted branch temp (was d6d48cc).
su@SUCHANGLI /e/eoe_client/android-app (master)

如果该分支没有合并到主分支会报错,可以用以下命令强制删除git branch -D <分支名>

总结:方式二更好理解,更安全,对于pull也可以更新代码到本地,相当于fetch+merge,多人写作的话不够安全。
如有错误请指正

原文作者: com360

一、 Git 命令初识

在正式介绍Git命令之前,先介绍一下Git 的基本命令和操作,对Git命令有一个总体的认识

示例:从Git 版本库的初始化,通常有两种方式:

1)git clone:这是一种较为简单的初始化方式,当你已经有一个远程的Git版本库,只需要在本地克隆一份

some_project

上面的命令就是将'git://github.com/someone/some_project.git'这个URL地址的远程版本库,完全克隆到本地some_project目录下

2)git init 和 git remote:这种方式稍微复杂一些,当你本地创建了一个工作目录,你可以进入这个目录,使用'git init'命令进行初始化;Git以后就会对该目录下的文件进行版本控制,这时候如果你需要将它放到远程服务器上,可以在远程服务器上创建一个目录,并把可访问的URL记录下来,此时你就可以利用'git remote add'命令来增加一个远程服务器端,

origin  git://github.com/someone/another_project.git

上面的命令就会增加URL地址为'git: //github.com/someone/another_project.git',名称为origin的远程服务器,以后提交代码的时候只需要使用 origin别名即可


二、 Git 常用命令


1) 远程仓库相关命令


检出仓库:        $ git clone git://github.com/jquery/jquery.git

查看远程仓库:$ git remote -v

添加远程仓库:$ git remote add [name] [url]

删除远程仓库:$ git remote rm [name]

修改远程仓库:$ git remote set-url --push [name] [newUrl]

拉取远程仓库:$ git pull [remoteName] [localBranchName]

推送远程仓库:$ git push [remoteName] [localBranchName]


*如果想把本地的某个分支test提交到远程仓库,并作为远程仓库的master分支,或者作为另外一个名叫test的分支,如下:


$git push origin test:master         // 提交本地test分支作为远程的master分支

$git push origin test:test              // 提交本地test分支作为远程的test分支


2)分支(branch)操作相关命令

查看本地分支:$ git branch

查看远程分支:$ git branch -r

创建本地分支:$ git branch [name] ----注意新分支创建后不会自动切换为当前分支

切换分支:$ git checkout [name]

创建新分支并立即切换到新分支:$ git checkout -b [name]

删除分支:$ git branch -d [name] ---- -d选项只能删除已经参与了合并的分支,对于未有合并的分支是无法删除的。如果想强制删除一个分支,可以使用-D选项

合并分支:$ git merge [name] ----将名称为[name]的分支与当前分支合并

创建远程分支(本地分支push到远程):$ git push origin [name]

删除远程分支:$ git push origin :heads/[name] 或 $ gitpush origin :[name] 


*创建空的分支:(执行命令之前记得先提交你当前分支的修改,否则会被强制删干净没得后悔)


$git symbolic-ref HEAD refs/heads/[name]

$rm .git/index

$git clean -fdx


3)版本(tag)操作相关命令

查看版本:$ git tag

创建版本:$ git tag [name]

删除版本:$ git tag -d [name]

查看远程版本:$ git tag -r

创建远程版本(本地版本push到远程):$ git push origin [name]

删除远程版本:$ git push origin :refs/tags/[name]

合并远程仓库的tag到本地:$ git pull origin --tags

上传本地tag到远程仓库:$ git push origin --tags

创建带注释的tag:$ git tag -a [name] -m 'yourMessage'

4) 子模块(submodule)相关操作命令

添加子模块:$ git submodule add [url] [path]

如:$git submodule add git://github.com/soberh/ui-libs.git src/main/webapp/ui-libs

初始化子模块:$ git submodule init  ----只在首次检出仓库时运行一次就行

更新子模块:$ git submodule update ----每次更新或切换分支后都需要运行一下


删除子模块:(分4步走哦)

1) $ git rm --cached [path]

2) 编辑“.gitmodules”文件,将子模块的相关配置节点删除掉

3) 编辑“ .git/config”文件,将子模块的相关配置节点删除掉

4) 手动删除子模块残留的目录

5)忽略一些文件、文件夹不提交

在仓库根目录下创建名称为“.gitignore”的文件,写入不需要的文件夹名或文件,每个元素占一行即可,如

target

bin

*.db

三、 Git 命令详解

现在我们有了本地和远程的版本库,让我们来试着用用Git的基本命令:

git pull:从其他的版本库(既可以是远程的也可以是本地的)将代码更新到本地,例如:'git pull origin master'就是将origin这个版本库的代码更新到本地的master主枝,该功能类似于SVN的update

git add:是将当前更改或者新增的文件加入到Git的索引中,加入到Git的索引中就表示记入了版本历史中,这也是提交之前所需要执行的一步,例如'git add app/model/user.rb'就会增加app/model/user.rb文件到Git的索引中,该功能类似于SVN的add

git rm:从当前的工作空间中和索引中删除文件,例如'git rm app/model/user.rb',该功能类似于SVN的rm、del

git commit:提交当前工作空间的修改内容,类似于SVN的commit命令,例如'git commit -m story #3, add user model',提交的时候必须用-m来输入一条提交信息,该功能类似于SVN的commit

git push:将本地commit的代码更新到远程版本库中,例如'git push origin'就会将本地的代码更新到名为orgin的远程版本库中

git log:查看历史日志,该功能类似于SVN的log

git revert:还原一个版本的修改,必须提供一个具体的Git版本号,例如'git revert bbaf6fb5060b4875b18ff9ff637ce118256d6f20',Git的版本号都是生成的一个哈希值

 

上面的命令几乎都是每个版本控制工具所公有的,下面就开始尝试一下Git独有的一些命令:

git branch:对分支的增、删、查等操作,例如'git branch new_branch'会从当前的工作版本创建一个叫做new_branch的新分支,'git branch -D new_branch'就会强制删除叫做new_branch的分支,'git branch'就会列出本地所有的分支

git checkout:Git的checkout有两个作用,其一是在不同的branch之间进行切换,例如'git checkout new_branch'就会切换到new_branch的分支上去;另一个功能是还原代码的作用,例如'git checkout app/model/user.rb'就会将user.rb文件从上一个已提交的版本中更新回来,未提交的内容全部会回滚

git rebase:用下面两幅图解释会比较清楚一些,rebase命令执行后,实际上是将分支点从C移到了G,这样分支也就具有了从C到G的功能

git stash:将当前未提交的工作存入Git工作栈中,时机成熟的时候再应用回来,这里暂时提一下这个命令的用法,后面在技巧篇会重点讲解

git config:利用这个命令可以新增、更改Git的各种设置,例如'git config branch.master.remote origin'就将master的远程版本库设置为别名叫做origin版本库,后面在技巧篇会利用这个命令个性化设置你的Git,为你打造独一无二的 Git

git tag:可以将某个具体的版本打上一个标签,这样你就不需要记忆复杂的版本号哈希值了,例如你可以使用'git tag revert_version bbaf6fb5060b4875b18ff9ff637ce118256d6f20'来标记这个被你还原的版本,那么以后你想查看该版本时,就可以使用 revert_version标签名,而不是哈希值了



【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
ppGGiSfbs6Lj