mac安装git
$> xcode-select --install
$ git branch -a
$ git checkout branch_name
$ git branch -D branch_name
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git reset HEAD <file>..." to unstage)
(use "git checkout -- <file>..." to discard changes in working directory)
Untracked files:
(use "git add <file>..." to include in what will be committed)
no changes added to commit (use "git add" and/or "git commit -a")
$ git log
commit 003
Author:
Date:
update 1.txt
commit 002
Author:
Date:
add 1.txt
commit 001
Author:
Date:
Initial empty repository
也可以通过Git Extensions打开repository(档案库)查看分支
$ edit hello.c
$ git rm goodbye.c
$ git add hello.c
$ git commit -m "提交的描述信息"
or: git commit -a
Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.
$ edit hello.c
$ rm goodbye.c
$ git commit -a -m "提交的描述信息"
$ git status | grep unmerged
unmerged: hello.c
$ edit hello.c
$ git add hello.c
$ git commit
参考网址: Git 分支 - 分支的新建与合并
$ git remote add origin https://github.com/username/jekyll_demo.git $ git push origin master
$ git remote -v
origin https://github.com/username/jekyll_demo.git (fetch)
origin https://github.com/username/jekyll_demo.git (push)
// 本地创建分支并切换到该分支
$ git branch iss53
$ git checkout iss53
// 为该分支创建远程服务器分支并提交
$ git push origin iss53
To https://github.com/username/jekyll_demo.git
* [new branch] iss53 -> iss53
// git pull 之前需要执行:
$ git branch --set-upstream-to=origin/iss53 iss53
$ git clone git@git.ijie.com:open-api.git
$ git pull
git pull 遇到冲突(conflict)
$ git stash
Saved working directory and index state WIP on <branch>: <commit version>
HEAD is now at <commit version>
$ git status
On branch <branch>
Your branch is behind 'origin/<branch>' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
$ git pull
$ git stash pop
Dropped refs/stash@{0}
git reset --hard HEAD~3 会将最新的3次提交全部重置,就像没有提交过一样。
git reset --hard 38679ed709fd0a3767b79b93d0fba5bb8dd235f8 回退到38679ed709fd0a3767b79b93d0fba5bb8dd235f8 版本
根据--soft --mixed --hard,会对working tree和index和HEAD进行重置:
git reset --mixed:此为默认方式,不带任何参数的git reset,即是这种方式,它回退到某个版本,只保留源码,回退commit和index信息。
git reset --soft:回退到某个版本,只回退了commit的信息,不会恢复到index file一级。如果还要提交,直接commit即可。
git reset --hard:彻底回退到某个版本,本地的源码也会变为上一个版本的内容。
一般情况下回退版本:
再次提交本地代码:
忽略Visual Studio生成时的产生的文件
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
[Bb]in
[Dd]ebug*/
*.lib
*.sbr
obj/
[Rr]elease*/
_ReSharper*/
忽略C++产生的文件
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
参考网址:
备注:
Resubmit(git push) code to gerrit
1. copy gerrit checkout
2. git fetch --all -p
3. git rebase origin/<branch>
4. fixed conflicts
5. git add ...
6. git rebase --continue
7. git commit --amend
8. copy gerrit change-id
9. git push...
go back commit version:
1. git log -> find commit version
2. git reset commit version
3. git pull
4. git add
5. git commit
6. git push
参考网址: Git Stash用法