// 必须已经将分支完全合并到其上游分支或者HEAD中,否则会报not full merged 错误。
git branch -d
// 强制删除,未合并到上游分支或者HEAD中也能成功删除。
git branch -D // 等价于git branch -d -f
git commit --amend
- 修改之后会产生新的commit,并替代以前的commit
- 既可以修改commit的message,也可以修改commit的内容。修改内容时需要先执行
git add xx
命令,将需要追加到commit的内容添先加到暂存区。
git rebase -i "要修改commit上一次的commit"
// 根据实际需要选择对应的命令,面板上提示如下:
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
pick 'commit的id' //选作基准,剩下的commit合并进来
s '要合并进去commit的id' // 此处可以有多个
...
pick 'commit的id' // 不合并进去
- 将不连续的commit合并:
与连续commit合并的区别在于,需要调整commit的顺序,将需要合并进去的commit放在一起,其余操作一样。
git diff --cached
// 后面可以添加文件名,只比较某一些文件
// 比如 git diff --cached -- "文件名"
git diff // 同上面一样,可以后面加文件名
git reset HEAD
// 操作下来,感觉这个操作会工作区的文件变为和暂存区一样,然后自动提交至暂存区
git checkout -- "文件名"
网友评论