- Forums
- Scripts
- Basic Useful Git Notes and Terminal Commands
[related Title] Git Notes From A Class I Took In Udacity Free Course [4722], Last Updated: Mon Jun 24, 2024
edwin
Sat Jul 27, 2019
0 Comments
587 Visits
these are some GIT Notes I have taken over time that has helped me become better developer using GIT commands
The firs file is called:
GIT NOTES - FIRST TIME CONFIG.txt:
https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup
USER WINDOWS POWERSHELL INSTEAD OF CMD
$ git config --global user.name "John Doe"
$ git config --global user.email [email protected]
While on a Windows system, if you want to use a different text editor, such as Notepad++, you can do the following:
On a x86 system
$ git config --global core.editor "'C:\Users\toshiba\Desktop\Apps\notepad++/notepad++.exe' -multiInst -nosession"
On a x64 system
$ git config --global core.editor "'C:\Users\toshiba\Desktop\Apps\Notepad++/notepad++.exe' -multiInst -nosession"
GIT-NOTES.txt
GOOD COMMON COMMANDS:
git log --oneline --graph --decorate --all
$ git shortlog
OR
$ git shortlog -s -n
# displays an alphabetical list of names and the commit messages that go along with them
Filter By Author
$ git log --author=Surma
$ git log --author="Paul Lewis"
How about we filter down to just the commits that reference the word "bug". We can do that with either of the following commands:
$ git log --grep=bug
$ git log --grep bug
https://www.udacity.com/wiki/ud775
https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf
it init [project-name]
http://classic.scottr.org/presentations/git-in-5-minutes/
git init
git init newrepo
git add filename
for a whole directory:
git init [directory name]
cd [directory name]
git add
Committing a Version
git commit -m "Adding files"
to remov long names, do this
npm install -g rimraf (if you havent' install it yet)
rimraf
windows delete "The specified path, file name, or both are too long"
http://superuser.com/questions/78434/how-to-delete-directories-with-path-names-too-long-for-normal-delete
REMOTE:
# add a remote repository on the website witout initializing
first create on the website:
https://github.com/edwinaquino/
example: https://github.com/edwinaquino/movietrailers
$ git remote add movietrailers https://github.com/edwinaquino/movietrailers.git
# NOW SHOW THE NEWLY CREATED REMOTE (THIS JUST SHOWS THE SHORTCUT NAME)
$ git remote
$ git push -u movietrailers master
# SEARCH FOR KEYWORD IN THE COMMENTS OF A COMMIT
$ git log -Skeyword
# SHOW ONLY THE HASH AND THE COMMENT IN THE LOG
$ git log --oneline
git log search by SHA code
# Find commit by hash SHA in Git
$ git show a2c25061
OR
$ git log --stat
The git log command has a flag that can be used to display the actual changes made to a file. The flag is --patch which can be shortened to just -p:
$ git log -p
How many files were changed by this commit
$ git show 8aa6668 --stat
Udacity Git Commit Message Style Guide
https://udacity.github.io/git-styleguide/
// ammend or change the last commit
git commit --amend
#############################################################
START .gitignore
#############################################################
Globbing lets you use special characters to match patterns/characters. In the .gitignore file, you can use the following:
blank lines can be used for spacing
# - marks line as a comment
* - matches 0 or more characters
? - matches 1 character
[abc] - matches a, b, or c
** - matches nested directories - a/**/z matches
a/z
a/b/z
a/b/c/z
So if all of the 50 images are JPEG images in the "samples" folder, we could add the following line to .gitignore to have Git ignore all 50 images.
samples/*.jpg
#############################################################
END .gitignore
#############################################################
#############################################################
Git Tag Command - start
#############################################################
Git Tag Command
Pay attention to what's shown (just the SHA and the commit message)
The command we'll be using to interact with the repository's tags is the git tag command:
$ git tag -a v1.0
CAREFUL: In the command above (git tag -a v1.0) the -a flag is used. This flag tells Git to create an annotated flag. If you don't provide the tag (i.e. git tag v1.0) then it'll create what's called a lightweight tag.
Annotated tags are recommended because they include a lot of extra information such as:
the person who made the tag
the date the tag was made
a message for the tag
Because of this, you should always use annotated tags.
#############################################################
Git Tag Command - end
#############################################################
TO VIEW THE FLAGS:
git log --decorate
DELETE A TAG
$ git tag -d v1.0
Adding A Tag To specific Commit
$ git tag -a v1.0 a87984
Branches In The Log
The branch information in the command prompt is helpful, but the clearest way to see it is by looking at the output of git log. But just like we had to use the --decorate flag to display Git tags, we need it to display branches.
$ git log --oneline --decorate
Delete A Branch
$ git branch -d sidebar
undoing changes
$ git commit --amend
// reverse commit
$ git revert
What Is A Revert?
When you tell Git to revert a specific commit, Git takes the changes that were made in commit and does the exact opposite of them. Let's break that down a bit. If a character is added in commit A, if Git reverts commit A, then Git will make a new commit where that character is deleted. It also works the other way where if a character/line is removed, then reverting that commit will add that content back!
// delete commits
$ git reset
DANGEROUS: squash commits together,
this will squash all your commits into a single commit
git rebase
// COMAINE THE LAST THREE INTO ONE COMMIT
$ git rebase -i HEAD~3
COMMITS MAP EXAMPLE: a-3-d-f-8-2-c-d
d is the current commit on the master branch
so with HEAD~3, the following commints will be combined:
8-2-c-d
GIT-Basic-Commands.txt
# LOCAL PROJECT
git init
git init newrepo
git add filename
git commit -a "Adding files"
# Repository
git clone --bare ~/your/repo/path project.git
Using git to get just the latest revision
git clone --depth=1 https://github.com/ampproject/amphtml.git
IF YOU GET THIS ERROR:
*** Please tell me who you are.
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
git config --global user.email "[email protected]"
git config --global user.name "Webune"
27-p4722-github-git-cheat-sheet.pdf