12
Git undo Michal Zmuda

Git undo changes

Embed Size (px)

DESCRIPTION

Git undo changes http://wp.me/p4Yp6B-4

Citation preview

Page 1: Git undo changes

Git undoMichal Zmuda

Page 2: Git undo changes

Agenda

Stories● undo local changes ● undo file changes to SHA● modify last commit● delete commit● undo local branch commits● reverse commit(s)● prepare and apply patch● undo rebase

Page 3: Git undo changes

undo local changes - tracked files

git reset --hard

* reset is reverse operation to git add* --hard - any changes to tracked files are discarded* light version for not staged files: git checkout .

Page 4: Git undo changes

undo local changes - untracked files

git clean -fd

* only untracked files are deleted* all untracked files and directories are deleted* -fdx option removes also ignored files

Page 5: Git undo changes

undo file changes to SHA

git checkout 816367 GrailsTask.groovygit commit -m "reverted GrailsTask.groovy"

Page 6: Git undo changes

modify last commit

git commit --amend

* file content or commit comment can be changed* last commit should not be pushed to remote repository before

Page 7: Git undo changes

delete commit

before: add few local commits

git rebase -iremove line with commit and exit vim (:wq)

* commits can be reordered, squashed and comments can be changed* delete commits only when they are not pushed to remote repository* if you remove everything, the rebase will be aborted

Page 8: Git undo changes

undo local branch commits

git reset --hard origin/master

* origin/master - remote branch

Page 9: Git undo changes

Reverse commit(s)

git revert 9973c1a --no-commit

* can be used to revert remote changes* --no-commit - use to preview changes* to revert range of revisions: 52ea36..0bbc55

Page 10: Git undo changes

Prepare and apply patch

Prepare patchgit diff LATEST_SHA OLDER_SHA > mypatch.patchgit diff 0bbc55 52ea36d > mypatch.patch

Apply patchgit apply mypatch.patch

* can be used to revert remote changes

Page 11: Git undo changes

undo rebase

add 2 commits and rebase interactive with squash and edit comments

Select history entrygit reflog

git reset --hard HEAD@{3}

* use only for local changes

Page 12: Git undo changes

Thanks