Hashem Nasarat
February 15, 2013
git help
<command>
git init
– Create a repository repo files
___
[ ] *
[___]
git add
– I want you to record the state of the following files ___
[ * ]
[___]
git commit
– Actually do it. (And attach a message describing changes) __________________
[ * (HEAD) message ]
[__________________]
git commit
(with no arguments) will open vim. Press i
, write the commit message, press Esc then save and quit, by typing :wq
___________________
[ * (HEAD) message3 ]
[ * message2 ]
[ * message ]
[___________________]
git rm
<filename>
git mv
<from-filename> <to-filename>
.git/config
file has detailsorigin
local remote
(laptop) (GitHub)
____ ____
[ * ] [ ]
[ * ] [ ]
[ * ] [ ]
[____] [____]
git push
local remote
(laptop) (GitHub)
____ push ____
[ * ] -----> [ * ]
[ * ] [ * ]
[ * ] [ * ]
[____] [____]
git push -f
It’s usually better to resolve conflicts rather than do this. This can lead to lost data)git clone
local remote local
(laptop) (GitHub) (halligan)
____ ____ clone ____
[ * ] [ * ] ------> [ * ]
[ * ] [ * ] [ * ]
[ * ] [ * ] [ * ]
[____] [____] [____]
git pull
local remote local
(laptop) (GitHub) (halligan)
____ ____ ____
[ * ] (push) [ * ] pull [ * ]
[ * ] -----> [ * ] ------> [ * ]
[ * ] [ * ] [ * ]
[ * ] [ * ] [ * ]
[____] [____] [____]
git pull
is usually bad form. Use git pull --rebase
gitk --all
git log --graph --oneline --all --decorate
Ctrl + r
, then start typing git log --graph
…)git diff
to see what was changed from the last commit)git add
<path[s]> – record these changes in the next commitgit commit
– make the commit, and add a messagegit add -p
to select exactly which changes within files are added)git reset
(without any arguments!) will undo git add
E.g. If the feature is: “ensure all img
tags have an alt
attribute”, a good commit will add alt
tags for every img
in one go, and NOT create a new commit for every changed img
tag, or every file that I change things in.
Add alt attribute to every img
As per Section 508 Amendment to the Rehabilitation Act of 1973
and the HTML 5 specification, every img should have an alt
attribute which "provides equivalent content for those who
cannot process images or who have image loading disabled".
git reset --hard
<commit>
* 31a3f57 (HEAD, master) Third commit
* 20ea82d Second commit
* 9ef5cfb First commit
git reset --hard 20ea82d
* 20ea82d (HEAD, master) Second commit
* 9ef5cfb First commit
git reflog
20ea82d HEAD@{0}: reset: moving to HEAD~1
31a3f57 HEAD@{1}: checkout: moving from 20ea82d to master
20ea82d HEAD@{2}: checkout: moving from master to HEAD~1
31a3f57 HEAD@{3}: commit: Third commit
20ea82d HEAD@{4}: commit: Second commit
9ef5cfb HEAD@{5}: commit (initial): First commit
git reset --hard 31a3f57
* 31a3f57 (HEAD, master) Third commit
* 20ea82d Second commit
* 9ef5cfb First commit
master
git branch -a
* 7a0fc15 Patch.hs: Fix incorrect editsToChangeHunks offsets
* e564f63 Make the type of Edit more general.
* | 0bbe999 Implements applyPatch
* | b6d7003 Implements sequencePatches
|/
* 6f2a864 Paralell patch changes
git branch
<branch-name>git branch -d
<branch-name>git checkout
<branch-name>git merge
<branch to merge in>
* ca5ac46 Merge branch 'master' of github.com:jmont/nor
|\
| * 7a0fc15 Patch.hs: Fix incorrect editsToChangeHunks offsets
| * e564f63 Make the type of Edit more general.
* | 0bbe999 Implements applyPatch
* | b6d7003 Implements sequencePatches
|/
* 6f2a864 Paralell patch changes
git rebase
<branch to rebase onto>
* 7a0fc15 Patch.hs: Fix incorrect editsToChangeHunks offsets
* e564f63 Make the type of Edit more general.
* 0bbe999 Implements applyPatch
* b6d7003 Implements sequencePatches
* 6f2a864 Paralell patch changes
git add .
and git commit
these lines
are not
in conflict
<<<<<<
THESE ARE IN CONFLICT!
======
These are in conflict.
>>>>>> version 2
these lines
are good too
remote remote
tuftsdev/ hnasar/
running-dogs running-dogs
____ ____
[ * ] fork [ * ]
[ * ] -----> [ * ]
[ * ] [ * ]
[____] [____]
git format-patch
<commit>) via email or posting on websites. remote remote
tuftsdev/ hnasar/
running-dogs running-dogs
____ ____
[_*__] <------ [ * ]
[ * ] pull [ * ]
[ * ] request [ * ]
[ * ] [ * ]
[____] [____]
git@github.com/
….git/config
filegit log --graph --oneline --all --decorate
)git checkout
<commit-hash> (e.g. git checkout 0dc4e6e
)
git checkout
a branch to “reattach” the HEADgit blame
<file> to see when and who last made changes to a part of a file.git show
<commit> displays the contents of a given commit.git rebase -i
<commit-ish>This work is licensed under the Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/.