标签:
为什么Git比其他版本控制系统设计得优秀,因为Git跟踪并管理的是修改,而非文件。
---------------------------------------------------------------
添加忽略的文件
git update-index --assume-unchaged dir
取消之前设置的 添加忽略文件设置
git update-index --no-assume-unchaged dir
git update-index --[no-]assume-unchanged
When these flags are specified, the object names recorded for the paths are not updated. Instead, these options
set and unset the "assume unchanged" bit for the paths. When the "assume unchanged" bit is on, Git stops
checking the working tree files for possible modifications, so you need to manually unset the bit to tell Git when
you change the working tree file. This is sometimes helpful when working with a big project on a filesystem that
has very slow lstat(2) system call (e.g. cifs).
This option can be also used as a coarse file-level mechanism to ignore uncommitted changes in tracked files
(akin to what .gitignore does for untracked files). Git will fail (gracefully) in case it needs to modify this file in the
index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need
to handle the situation manually.
---------------------------------------------------------------
$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"
注意git config命令的--global参数,用了这个参数,表示你这台机器上所有的Git仓库都会使用这个配置,当然也可以对某个仓库指定不同的用户名和Email地址。
---------------------------------------------------------------
Git 使用的一般流程:
git status
git add <files>
git commit -m "comments................."
git push
pull request
---------------------------------------------------------------
git add .
git stash
git stash lish
git stash apply
git stash pop
git stash apply stash@{1}
如果想删除一个stash
git stash drop <id>
删除所有stash
git stash clear
stash内容的恢复:
一是用git stash apply恢复,但是恢复后,stash内容并不删除,你需要用git stash drop来删除;
另一种方式是用git stash pop,恢复的同时把stash内容也删了:
---------------------------------------------------------------
git status 显示文件发生了改变,这个时候就可以用
git diff <filename>去查看改变了什么
查看最近的提交历史
git log
git log --pretty=oneline
Git提供了一个命令git reflog用来记录你的每一次命令:
git reflog
---------------------------------------------------------------
丢弃本地仓的修改
Git的版本回退速度非常快,因为Git在内部有个指向当前版本的HEAD指针,当你回退版本的时候,Git仅仅是把HEAD
从指向“你要回退的那个版本”。然后顺便把工作区的文件更新了。
roll back the code
git reset --hard HEAD^
git reset --hard HEAD^^
git reset --hard HEAD^^^
git reset --hard HEAD~100
git reset --hard 24513e54ad
---------------------------------------------------------------
丢弃暂存区的修改
可以把暂存区的修改撤销掉(unstage),重新放回工作区。
git reset HEAD <file>
---------------------------------------------------------------
丢弃工作区的修改
use "git checkout -- <file>..." to discard changes in working directory
git checkout -- <file>
命令git checkout -- readme.txt意思就是,把readme.txt文件在工作区的修改全部撤销,这里有两种情况:
一种是readme.txt自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;
一种是readme.txt已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。
总之,就是让这个文件回到最近一次git commit或git add时的状态。
---------------------------------------------------------------
删除文件
$ git status
# 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: test.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
现在你有两个选择:
1.确实要从版本库中删除该文件,那就用命令git rm删掉
git rm test.txt
git commit -m "remove the test.txt"
2.是删错了,误删了,因为版本库里还有呢,所以可以很轻松地把误删的文件恢复到最新版本:
git checkout --test.txt
---------------------------------------------------------------
Create a new repository on the command line
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/jiale0815/learngit.gitgit push -u origin master
Push an existing repository from the command line
git remote add origin https://github.com/jiale0815/learngit.gitgit push -u origin master
---------------------------------------------------------------
查看分支:
git branch
创建分支:
git branch <name>
切换分支:
git checkout <name>
创建+切换分支:
git checkout -b <name>
---------------------------------------------------------------
合并某分支到当前分支:
git merge <name>
合并分支时,加上--no-ff参数就可以用普通模式合并,合并后的历史有分支,能看出来曾经做过合并,而fast forward合并就看不出来曾经做过合并。
$ git merge --no-ff -m "merge with no-ff" dev
---------------------------------------------------------------
删除分支:
git branch -d <name>
强制删除分支
$ git branch -d feature-vulcan
error: The branch ‘feature-vulcan‘ is not fully merged.
If you are sure you want to delete it, run ‘git branch -D feature-vulcan‘.
$ git branch -D feature-vulcan
Deleted branch feature-vulcan (was 756d4af).
---------------------------------------------------------------
git fetch origin branchName
git merge FETCH_HEAD
git pull origin branchName
$ git branch -r
$ git clone https://kyle.bai@stash.crownpartners.com/scm/gsk/hybrisb2b.git
---------------------------------------------------------------
git 有三层配置文件仓库级,全局级,系统级。配置文件的权重是仓库>全局>系统
格式:git config [–local|–global|–system] -l
查看仓库级的config,即.git/.config,命令:git config –local -l
查看全局级的config,即C:\Users\jiale\.gitconfig,命令:git config –global -l
查看系统级的config,即D:\Git\etc\gitconfig,命令:git config –system -l
查看当前生效的配置,命令:git config -l,这个时候会显示最终三个配置文件计算后的配置信息
---------------------------------------------------------------
cygwin (select package to install)
git
linux
dos
---------------------------------------------------------------
Git 笔记
标签:
原文地址:http://www.cnblogs.com/kylebai/p/4529453.html