how to pull after forced update
1
|
|
this willResets the index and working tree. Any changes to tracked files in the working tree since are discarded.
当前工作目录的index和本地修改,都会被丢弃(丢弃的修改包括已经提交到本地的commit)
可以使用 --soft
If you want to actually keep whatever changes you’ve got locally, do a --soft
reset instead. which will update the commit history for the branch,
不会丢弃本地未提交的修改,但是会丢弃本地提交的修改。
另外还有两个参数 --keep --merge
,我在本地试了一下,都报错了,没有深入了解。
git rebase
You can replay your local commits ontop of any other commit/branch using git rebase 例如你在feature分支,你可以基于master分支对当期的分支rebase
1
|
|
this will invoke rebase in interactive mode where you can choose how to apply each individual commit that isn’t in the history you are rebasing on top of.
你也可以基于当期分支的之前的commit进行分子
1
|
|
相对于从倒退3个提交,开始rebase,这样你就可以对的多次提交进行合并。
如果你的分支已经push到了远端,那么在rebase之后,你要push的话,只能用 forced git push。
Throw away local commits in git
前面讲到的git reset就可以完成这个工作。例如你在master分支上
1
|
|
这样就可以达到需要的效果。
不要使用git revert, git revert会提交一个新的commit去revert原来的commit,这样在history中就可以看到。
git clean
http://stackoverflow.com/questions/61212/how-do-i-remove-local-untracked-files-from-my-current-git-branch
1
|
|
But beware… there’s no going back. Use -n
or --dry-run
to preview the damage you’ll do.
If you want to also remove directories, run git clean -f -d
or git clean -fd
If you just want to remove ignored files, run git clean -f -X
or git clean -fX
If you want to remove ignored as well as non-ignored files, run git clean -f -x
or git clean -fx
Note the case difference on the X
for the two latter commands.
If clean.requireForce
is set to “true” (the default) in your configuration, then unless you specify -f nothing will actually happen.
See the git-clean docs for more information.