您的位置:首页 > 其它

git_ABC

2016-04-14 21:25 295 查看
锲而不舍,金石可镂;锲而舍之,朽木不折--------------------持续更新,每天进步一点点

git config user

$ git config --global user.name "John Doe"

$ git config --global user.email johndoe@example.com

check config info

$ git config --list

check special info
$ git config user.name

note:

1. branch 里面没有内容,也没有任何提交记录 ----git branch 不显示没有任何内容得branch

2. 第一次提交后会默认自动创建master  branch

git add *****   #指定要add到跟踪状态的文件(. 表示当前目录)

git commit –am “*****” #写上提交的日志信息

git push origin master     #上传代码到服务器

2016-11-02 10:38:45

$ git commit --amend(re-commit also  edit comment)

$ git reset HEAD test.cpp(cancle stash file to unstash)

$ git checkout  -- test.cpp(to discard changes in working directory)

对于不需要push到git服务器的工程文件与编译中间文件,可以创建一下.gitignore加入匹配来过滤

git branch test(创建一个本地分支test)

git branch -d test(删除本地分支test)

git checkout test(切换到本地分支test)

git checkout -b test  ==   git branch test + git checkout test

git branch -v(查看各个分支最后一个提交对象的信息)

# sunsun,万马奔腾,切记要把分支rebase到master分支必须要首先切换到master分支,要不会出现问题,弄好半天,一万个驼羊

git rebase test(把test分支rebase到master分支)

#切记,rebase或者 merge后一定要push才能使使远程的分支确保更新到master分支,一定要记住和服务器打交道的命令只有 push 和 pull

git log --stat    --stat选项,它会显示在每个提交(commit)中哪些文件被修改了, 这些文件分别添加或删除了多少行内容

git log -p   查看详细的提交内容,-p是展开的意思

2014/8/27 11:41:10

TAG

git tag 列出git中现有标签(列表是按照字母表顺序给出的)

带注释的标签

git tag -a v1.4 -m 'version 1.4'   -a 表示新增(add)一个标签    -m 表示注释信息(message)

git tag -d v1.4(delete name v1.4 tag)----Local

git push origin :refs/tags/v1.4  (delete name v1.4 tag from server)----Server

git push origin --tags(commit all tags to server)------Server   默认情况下,'git push'命令不会将标签上传到远程服务器上,必须在'git push'命令后明确添加--tags选项

##all progrss:

git add .

git commit -m “fixed some bugs”

git tag -a v1.4 -m “Release version 1.4″

git push origin master

git push origin -–tags

2014/10/23 11:24:32

git add -u(--update) [<path>] 把<path>中所有tracked文件中被修改过或已删除文件的信息添加到索引库,它不会处理untracted的文件(省略<path>表示 . ,即当前目录)

git add -A(--all) ----linux下严格区分大小写  [<path>]表示把<path>中所有tracked文件中被修改过或已删除文件和所有untracted的文件信息添加到索引库(省略<path>表示 . ,即当前目录)

2015/1/10 11:16:52

if git add ERROR  "git reset HEAD <file>..." to unstage

2015/1/13 14:04:05

1.$ git branch -a

  * master

  remotes/origin/HEAD -> origin/master

  remotes/origin/master

  remotes/origin/xxxx_test

  remotes/origin/xxxx_fixbug

2.git rebase origin/xxxx_test(origin/xxxx_test branch rebase to master branch)

3.git rebase --continue(all conflicts fixed: run "git rebase --continue")

2015/1/14 15:48:22

$ git pull origin xxxx_test(pull server code to local)

$ git commit -m "merge master"(pull complete merge )

$ git push origin  xxxx_test(code push to server)

git push operator

push  (语法git push  服务器   本地分支:远程分支)------ git push origin master == git push origin master:master

跟踪远程分支  git checkout -b [分支名] [远程名]/[分支名]

从远程分支 checkout 出来的本地分支,称为 跟踪分支 (tracking branch)

git checkout -b xxxx_test origin/xxxx_test(创建一个远程本地分支xxxx_test)---------git checkout --track origin/xxxx_test(versio1.6.2up)

删除一个远程分支

git push [远程名] :[分支名]

git push origin :serverfix

2015/1/15 17:04:45

merge(not to rebase(re-find base to merge))

git checkout xxxx_test

git merge master(master merge to xxxx_test)

git add .

git commit -m "xxxxxx"

git push origin xxxx_test(merge after do xxxx_test code push to origin)

2015/1/19 17:29:36

merge(not to rebase(re-find base to merge))

git checkout xxxx_test

git merge master(master merge to xxxx_test)-----------no conflicts merge succeed

git add .  (not need)

git commit -m "xxxxxx"  (not nedd)

git push origin xxxx_test(merge after do xxxx_test code push to origin)-------no conflicts direct push to current branch

2015/4/22 17:30:32

batch delete branch

git branch |grep 'branchName' |xargs git branch -D(从分支列表中匹配到指定分支,然后一个一个(分成小块)传递给删除分支的命令,最后进行删除)

这是通过 shell 管道命令来实现的批量删除分支的功能

git branch 输出当前分支列表

grep 是对 git branch 的输出结果进行匹配,匹配值当然就是 branchName

xargs 的作用是将参数列表转换成小块分段传递给其他命令

$ git branch |grep 'icon' |xargs git branch -D(branchName evrything txt)

Deleted branch Align_icon_debug (was fbc85ab).

Deleted branch test_icon (was b17fd2e).

2015/5/7 11:01:59

Stashing

git stash

git stash list

$ git stash list

stash@{0}: WIP on master: 049d078 added the index file

stash@{1}: WIP on master: c264051 Revert "added file_size"

stash@{2}: WIP on master: 21d80a5 added number to log

git stash apply(statshing current work dir)

git stash apply stash@{2}

git stash pop(similar stack pop top(stash@{2}))

2015/5/11 10:55:33

创建远程分支

1.首先需要有个本地的branch(git checkout -b august_test)

$ git checkout -b august_test

Switched to a new branch 'august_test'

2.git push (远程仓库名) (分支名)( git push origin august_test)

$ git push origin august_test

Total 0 (delta 0), reused 0 (delta 0)

To git@192.168.1.75:testing.git

 * [new branch]      august_test -> august_test

$ git branch -a

* august_test

  master

  remotes/origin/HEAD -> origin/master

  remotes/origin/august_test

  remotes/origin/master

3.创建完成后,还不能立马使用远程分支,还需要创建一个tracking branch

$ git pull

There is no tracking information for the current branch.

Please specify which branch you want to merge with.

See git-pull(1) for details

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> august_test

4. Deleted a remote branch

git push [远程名] :[分支名](git push origin :august_test)

$ git push origin :august_test

To git@192.168.1.75:testing.git

 - [deleted]         august_test

$ git branch -a

* august_test

  master

  remotes/origin/HEAD -> origin/master

  remotes/origin/master

2015/5/20 18:23:35

git reset --hard   recover

1. git reflog

2. git reset commitId

2016-05-13 16:34:25 

error: insufficient permission for adding an object to repository database .git/objects

error: core/java/android/os/PowerManager.java: failed to insert into database

error: unable to index file core/java/android/os/PowerManager.java

fatal: updating files failed

提示是insufficient permission,所以首先想到的就是可能当前用户没有权限操作该目录,根据提示到相应目录下查看,果然该目录已经被修改过。

根据提示找到拥有者发生变化的目录,使用 chown -R xxx:xxx   dir/  切换到当前需要提交记录的拥有者

敬请期待,持续更新中.......
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  git ABC