*添加文件到git仓库分两步:
1、使用git add filename ;可分多次使用,添加多个文件到暂存区
2、使用git commit -m “说明” ;完成提交到分支
*查看工作区状态,使用git status 命令;如果提示有修改可使用git diff filename 查看修改内容
*HEAD指向当前版本,HEAD^表示上一个版本,HEAD^^上上一个版本……HEAD~100指向之前第100个版本。
*回退版本:使用git log查看提交历史;使用git log --pretty=oneline 精简显示
使用git reset --hard commit_id 回退到版本号为commit_id的版本
*回退版本之后如果想再看改回来,可以使用git reflog 查看历史命令,找出想改回的版本号,再使用git reset hard commit_id 返回即可。
*注意:git跟踪并管理的是修改,而不是文件,如果一个文件修改并add之后,再次修改,如果不再次add就提交的话,只会提交第一次的修改。命令详解可查看“Linux命令大全”。
git是linux下的版本管理工具,类似于CVS。git没有登陆与退出的概念,每次 *** 作都要求输入密码(当然也可以做到不用每次都输入密码)。
0.首先要设置环境变量,否则每次提交信息与本人不匹配:
GIT_AUTHOR_EMAIL=xxx@163.com
GIT_AUTHOR_NAME='Yang XX'
GIT_COMMITTER_EMAIL=xxx@163.com
GIT_COMMITTER_NAME='Yang XX'
常用的git命令有:
1.git-clone username@ipaddress:/xxx/xxx(服务器上的工程目录,要求记住)
该命令为第一次登陆工程目录时使用,目的是拷贝工程目录内容,以后的所有 *** 作最好都在该目录下。
2.git-add filename
添加文件,只在本机目录下有效。
3.git-commit -m "comment about this operation"
关于本次 *** 作的注释,只提交到本机目录下。
4.git-push
提交变化到服务器。真正有效的 *** 作
5.git-pull
将服务器上该工程目录下的变化拷贝到本机目录中。也用于每次提交之后交验 *** 作是否有效。
6.git-diff
显示本机与服务器中工程目录内容的不同。
7.git-checkout branchname
切换分支。默认每次均在master分支下 *** 作。
8.gitk --all
以图形界面的方式显示所有 *** 作及注释。
你是你是要通过git命令上传东西,还是想上传git到服务器上面,你可以先通过yum安装git
# yum install git已加载插件:fastestmirror, refresh-packagekit, security
设置安装进程
Loading mirror speeds linuxprobe.com from cached hostfile
base | 3.7 kB 00:00
epel | 4.3 kB 00:00
epel/primary_db | 5.9 MB 00:05
extras | 3.4 kB 00:00
hhvm | 2.9 kB 00:00
shells_fish_release_2 | 1.2 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 821 kB 00:01
upgrade | 1.9 kB 00:00
virtualbox/signature | 181 B 00:00
virtualbox/signature | 1.1 kB 00:00 ...
包 git-1.7.1-8.el6.x86_64 已安装并且是最新版本
无须任何处理 #git --help
usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]
[-p|--paginate|--no-pager] [--no-replace-objects]
[--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]
[--help] COMMAND [ARGS]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and merge with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG
See 'git help COMMAND' for more information on a specific command.
下面我给介绍一种从本地上传到服务器的命令:
命令rz和sz命令,首先你需要安装lrzsz库
#rz --helprz version 0.12.20
Usage: rz [options] [filename.if.xmodem]
Receive files with ZMODEM/YMODEM/XMODEM protocol
(X) = option applies to XMODEM only
(Y) = option applies to YMODEM only
(Z) = option applies to ZMODEM only
-+, --append append to existing files
-a, --ascii ASCII transfer (change CR/LF to LF)
-b, --binary binary transfer
-B, --bufsize N buffer N bytes (N==auto: buffer whole file)
-c, --with-crc Use 16 bit CRC (X)
-C, --allow-remote-commands allow execution of remote commands (Z)
-D, --null write all received data to /dev/null
--delay-startup N sleep N seconds before doing anything
-e, --escape Escape control characters (Z)
-E, --rename rename any files already existing
--errors N generate CRC error every N bytes (debugging)
-h, --help Help, print this usage message
-m, --min-bps N stop transmission if BPS below N
-M, --min-bps-time N for at least N seconds (default: 120)
-O, --disable-timeouts disable timeout code, wait forever for data
--o-sync open output file(s) in synchronous write mode
-p, --protect protect existing files
-q, --quiet quiet, no progress reports
-r, --resume try to resume interrupted file transfer (Z)
-R, --restricted restricted, more secure mode
-s, --stop-at {HH:MM|+N} stop transmission at HH:MM or in N seconds
-S, --timesync request remote time (twice: set local time)
--syslog[=off] turn syslog on or off, if possible
-t, --timeout N set timeout to N tenths of a second
-u, --keep-uppercase keep upper case filenames
-U, --unrestrict disable restricted mode (if allowed to)
-v, --verbose be verbose, provide debugging information
-w, --windowsize N Window is N bytes (Z)
-X --xmodem use XMODEM protocol
-y, --overwrite Yes, clobber existing file if any
--ymodem use YMODEM protocol
-Z, --zmodem use ZMODEM protocol
short options use the same arguments as the long ones
#sz --help
sz version 0.12.20
Usage: sz [options] file ...
or: sz [options] -{c|i} COMMAND
Send file(s) with ZMODEM/YMODEM/XMODEM protocol
(X) = option applies to XMODEM only
(Y) = option applies to YMODEM only
(Z) = option applies to ZMODEM only
-+, --append append to existing destination file (Z)
-2, --twostop use 2 stop bits
-4, --try-4k go up to 4K blocksize
--start-4k start with 4K blocksize (doesn't try 8)
-8, --try-8k go up to 8K blocksize
--start-8k start with 8K blocksize
-a, --ascii ASCII transfer (change CR/LF to LF)
-b, --binary binary transfer
-B, --bufsize N buffer N bytes (N==auto: buffer whole file)
-c, --command COMMAND execute remote command COMMAND (Z)
-C, --command-tries N try N times to execute a command (Z)
-d, --dot-to-slash change '.' to '/' in pathnames (Y/Z)
--delay-startup N sleep N seconds before doing anything
-e, --escape escape all control characters (Z)
-E, --rename force receiver to rename files it already has
-f, --full-path send full pathname (Y/Z)
-i, --immediate-command CMD send remote CMD, return immediately (Z)
-h, --help print this usage message
-k, --1k send 1024 byte packets (X)
-L, --packetlen N limit subpacket length to N bytes (Z)
-l, --framelen N limit frame length to N bytes (l>=L) (Z)
-m, --min-bps N stop transmission if BPS below N
-M, --min-bps-time N for at least N seconds (default: 120)
-n, --newer send file if source newer (Z)
-N, --newer-or-longer send file if source newer or longer (Z)
-o, --16-bit-crc use 16 bit CRC instead of 32 bit CRC (Z)
-O, --disable-timeouts disable timeout code, wait forever
-p, --protect protect existing destination file (Z)
-r, --resume resume interrupted file transfer (Z)
-R, --restricted restricted, more secure mode
-q, --quiet quiet (no progress reports)
-s, --stop-at {HH:MM|+N} stop transmission at HH:MM or in N seconds
--tcp build a TCP connection to transmit files
--tcp-server open socket, wait for connection
-u, --unlink unlink file after transmission
-U, --unrestrict turn off restricted mode (if allowed to)
-v, --verbose be verbose, provide debugging information
-w, --windowsize N Window is N bytes (Z)
-X, --xmodem use XMODEM protocol
-y, --overwrite overwrite existing files
-Y, --overwrite-or-skip overwrite existing files, else skip
--ymodem use YMODEM protocol
-Z, --zmodem use ZMODEM protocol
short options use the same arguments as the long ones
More information can be used for reference linuxprobe.com。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)