Remember that the HEAD is Git’s way of referring to the current snapshot
- Merging takes the contents of a source branch and integrated them with a target branch. In this process, only the target branch is changed.
- This will create a "Merge commit" in the feature branch that holds the history of both branches
http://here.streamlinedstudio.com/35d39b314931
git stash list
lists out all stashesgit stash apply
applies latest saved stash to the working areagit stash apply stash@{0}
applies designated saved stash. Stash names look likestash@{<NUMBER>}
in the stash listgit stash pop
applies the stash (just likeapply
) but then removes that stash from the stash listgit stash --include-untracked
wil stash any new files in the workina area, without thisgit stash
will not stash any new files/folders in the working area.git stash drop
remove last stashgit stash drop stash@{<NUMBER>}
remove designated stash- `git stash save "NAME YOUR STASH HERE"
git add -p
allows you to stage commits in hunks to pick and choose what changes you want to do
A "checkout" is the act of switching between different versions of a target entity. It operates upon three distinct entities: files, commits, and branches.
git checkout -
shortcut for checking out last branch
How to undo a commit with git checkout
git log:
4444444 crazy commit that needs to be removed
3333333 third commit
2222222 second commit
1111111 first commit
- Check out the commit before the one you want to remove:
git checkout 3333333
(Enters a detached HEAD state*) git log
will not contain the commit or commits from3333333
on- Check out a new branch:
git checkout -b new_branch_without_crazy_commit
4444444
commit is now gone on the new branch
- This means you are no longer working on any branch. In a detached state, any new commits you make will be orphaned when you change branches back to an established branch. Orphaned commits are up for deletion by Git's garbage collector. The garbage collector runs on a configured interval and permanently destroys orphaned commits. To prevent orphaned commits from being garbage collected, we need to ensure we are on a branch.
--amend --no-edit
allows you to edit the previous commit’s message without adding another commit
--amend -m <COMMMIT MESSAGE>
allows you to change the previous commit message name
--no-edit
lets you ammend changes without specifying a new commit message (just uses the old commit message)
Amended commits are actually entirely new commits and the previous commit will no longer be on your current branch.
- 3 options:
--soft
,--mixed
(default),--hard
--soft
Moves head and current branch--mixed
Moves head and current branch, resets the staging area--hard
Moves head and current branch, resets the staging area, and resets the working area
git reset -- <FILE>
- Resets the staging area
git reset
or git reset --mixed
will move staged changes back to the working directory
`git reset --hard - Resets back to the commit, other commits above the specified commit will be removed from history.
If we have a shared remote repository that had the removed commits pushed to it, and we try to git push a branch where we have reset the history, Git will catch this and throw an error. Git will assume that the branch being pushed is not up to date because of it's missing commits. In these scenarios, git revert should be the preferred undo method.
The preferred method of undoing shared history is git revert. A revert is safer than a reset because it will not remove any commits from a shared history. A revert will retain the commits you want to undo and create a new commit that inverts the undesired commit. This method is safer for shared remote collaboration because a remote developer can then pull the branch and receive the new revert commit which undoes the undesired commit.
echo "HELLO" > hello.txt
creates a hello.txt file and writes HELLO in itcat hello.txt
shows contents of hello.txtvim hello.txt
opens vim editor to edit.i
to begin editing.esc
to exit edit mode.:wq
to save and exit.:q
exit and not save.