Git的一些操作
比较基础的不提了,文档一大堆,工程中遇到的一些操作自己记录一下
git-scm 基本都有了,记录的这些操作当然也有 git-scm中文 git course一个在线的教程,自己跑了一遍还挺不错的
- 删除一个远程分支
1 2 3 4
#As of Git v1.7.0, you can delete a remote branch using $ git push origin --delete <branchName> #which is easier to remember than $ git push origin :<branchName>
- 回退一次提交how-do-you-undo-the-last-commit
1 2 3 4 5 6
# Undo a commit and redo $ git commit ... (1) $ git reset --soft HEAD~1 (2) #<< edit files as necessary >> (3) $ git add .... (4) $ git commit -c ORIG_HEAD (5)
This is what you want to undo This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message1, or both. Leaves working tree as it was before “commit”. Make corrections to working tree files. Stage changes for commit. Commit the changes, reusing the old commit message. reset copied the old head to .git/ORIG_HEAD; commit with -c ORIG_HEAD will open an editor, which initially contains the log message from the old commit and allows you to edit it. If you do not need to edit the message, you could use the -C option instead. Editor’s note 1: You don’t need to reset to an earlier commit if “you misspelled your commit message”. If you reset, git will not link new activity to the previous commit in any way, giving you a blank slate for a new commit message. The easier option is git commit –amend, which will open your default commit message editor pre-populated with the last commit message.
Beware however that if you have added any new changes to the index, using commit –amend will add them to your previous commit.
- 只提取某一次提交的内容 以前很多时候多分支用的不好的时候,经常改乱了分支,合并代码没有办法有时候不得不手动改一遍,直到我知道了一个命令
1
$ git cherry-pick commit-hash