[go: up one dir, main page]

Menu

[d3172a]: / git-cmd  Maximize  Restore  History

Download this file

200 lines (162 with data), 4.3 kB

git add <filename>
git commit -m "info"
git push origin master / git push

mkdir gittest
cd gittest
mkdir repo
git init --bare repo
mkdir checkout
cd checkout
git clone ram@127.0.0.1:gittest/repo
cd repo
echo "hello" > hello
git add hello
git commit -m "add file hello"
git push origin master
git log

cd ~/gittest
mkdir checkout1
cd checkout1/
git clone ~/gittest/repo
cd repo/
echo "test1" > test1
git add test1
git commit -m "add test1"
git push origin master
git log

cd ~/gittest/checkout/repo
git pull

git rm hello
git rm -r dir

<branch>
git branch
查看本地分支
git branch -r
查看远程分支
git checkout -b r1
创建r1分支并切换到r1分支

切换分支:
$ git checkout r1
Switched to branch 'r1'
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

git push origin r1
将本地分支r1添加到服务器上,origin表示服务器

切换到r1分支,修改代码
git push origin r1
提交修改到r1分支

切换分支时,本地代码也会跟着分支变化。

clone的时候可以指定分支:
git clone ram@127.0.0.1:/var/repo -b r1

删除分支:
$ git branch -d r1
error: The branch 'r1' is not fully merged.
If you are sure you want to delete it, run 'git branch -D r1'.

删除本地分支:
git branch -D r1
删除远程分支:
git branch -r -D origin/r1


$ git branch -v
* master 648f145 hello master
  r1     7f63c78 hello r1

$ git branch --merge
* master
$ git branch --no-merge
  r1

$ git merge branch master r1
Updating 648f145..7f63c78
Fast-forward
 hello.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
$ git branch --no-merge
$ git branch --merge
* master
  r1
$ git branch -d r1
Deleted branch r1 (was 7f63c78).
$ git branch -r -d origin/r1
Deleted remote branch origin/r1 (was 92445e3).

<tag>
$ git tag -a beta1
$ git tag
beta1
$ git tag -a beta2 -m "beta 2"
$ git tag
beta1
beta2
$ git tag -d beta1
Deleted tag 'beta1' (was 63e34a5)
$ git tag -d beta2
Deleted tag 'beta2' (was fc20089)
$ git tag
$

$ git tag v0.1 -m "version 0.1"
$ git tag v0.2 -m "version 0.2"
$ git tag
v0.1
v0.2
$ git push --tags
ram@127.0.0.1's password: 
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 290 bytes | 0 bytes/s, done.
Total 2 (delta 0), reused 0 (delta 0)
To ram@127.0.0.1:/var/repo
 * [new tag]         v0.1 -> v0.1
 * [new tag]         v0.2 -> v0.2


使用下面命令放弃当前的所有commit:
git reset --hard origin/<branch>
例如:
git reset --hard origin/master

git reset HEAD~

如何修改上一笔提交的信息:
$ git rebase -i HEAD~2
这个命令出来之后,会出来两行:
pick:*******
pick:*******
如果你要修改哪个,就把那行的pick改成edit,然后退出。
现在可以使用下面的命令来修改信息了:
$ git commit --amend
最后恢复回去:
$ git rebase --continue

git status = svn st
git diff   = svn diff
git log    = svn log

fatal: unable to access 'http://git.code.sf.net/p/ramonelinux/code.git/': The requested URL returned error: 403
$ git remote set-url origin https://git.code.sf.net/p/ramonelinux/code.git

fatal: unable to access 'https://git.code.sf.net/p/ramonelinux/code.git/': SSL certificate problem: unable to get local issuer certificate
$ git config --global http.sslVerify false

<patch>
git commit --amend
git format-patch origin
git format-patch -1


git add hello.c
git commit -s -a
git format-patch -1
./scripts/checkpatch.pl 0001-hello.patch

./scripts/checkpatch.pl -f hello.c

git log
git revert xxxx(commit ID)
(use "git am --skip" to skip this patch)
(use "git am --abort" to restore the original branch)

patch -Np1 < 0001-hello.patch
patch -R -Np1 < 0001-hello.patch
git apply 0001-hello.patch
git apply -R 0001-hello.patch
git am 0001-hello.patch

没有签名:
ERROR: Missing Signed-off-by: line(s)
git commit -s

创建了文件:
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#13: 
new file mode 100644

正确的结果:
./scripts/checkpatch.pl 0001-hello.patch 
total: 0 errors, 0 warnings, 10 lines checked

0001-hello.patch has no obvious style problems and is ready for submission.

# for short commit id:
git log --oneline

git blame file.c