Git:命令

来自WHY42

Fork/工作流

在使用git fork了其他人的项目后,这个项目就会在自己的git空间复制出来,这时如果人家的版本更新了怎么办?

git clone https://git.oschina.net/solee-linux/eova.git

cd eova
git remote add eova-master https://git.oschina.net/eova/eova.git
git fetch eova-master
git pull eova-master master

git fetch origin master:tmp
git diff tmp 
git merge tmp

pull=fetch+merge

分支操作

git branch new-branch
git checkout new-branch
#以上两个命令等同于
git checkout -b new-branch

git fetch
git checkout -b local-branch origin/remote-branch
git push origin local-branch:remote-branch

git push remote local-branch:remote-branch

git push -u origin remote-branch

git branch -a
git branch -d alpha-1

COMMIT记录

git log            #查看提交记录
git commit --amend #修改上一次提交日志
git show commit-id

如果需要修改多次提交记录,或者合并commit,则

git rebase -i HEAF~6
# '-i'或'--interactive'参数调用交互模式

进入编辑界面:

  1 pick f50ebb6 added a secondary datasource, *** THIS MAY AFFECT PROD ENV ***,     and added multi-production category service
  2 pick 2bed616 updated dmp category response
  3 pick 879693f added category filter
  4 pick 284c5a6 added another category detail api for multi-product business
  5 pick 0121db1 fixed a bug where category names is not correct in category det    ail api
  6 pick 24ccf25 NEG-2529: (lihaifeng) updated category detail api
  7
  8 # Rebase 4c79356..24ccf25 onto 4c79356 (6 commands)
  9 #
 10 # Commands:
 11 # p, pick = use commit
 12 # r, reword = use commit, but edit the commit message
 13 # e, edit = use commit, but stop for amending
 14 # s, squash = use commit, but meld into previous commit
 15 # f, fixup = like "squash", but discard this commit's log message
 16 # x, exec = run command (the rest of the line) using shell
 17 # d, drop = remove commit

撤销操作

git checkout src/main/java/Xx.java
git checkout .
git clean -xdf
git reset --hard                    #撤销commit


git reset <commit-id> --hard
git cherry-pick <some-commit-id>

初始化

git init
git remote -v
git remote add osc git@git.oschina.net:solee-linux/spring-cloud-example.git
git pull osc master --allow-unrelated-histories
git push osc master

分支操作

git checkout master
git pull
git checkout -b release_xx
git tag release_20180801
git push origin release_xx
git push --tags