Git
$ git diff -r HEAD. The -r flag means "compare to a particular revision", and HEAD is a shortcut meaning "the most recent commit".
$ git commit -m "Program appears to have become self-aware.“$ git commit --amend - m "new message"$ git log (path/file.csv)
$ git show (first characters from a commit)
Used in git hub!
- git status: shows status of tracked and untracked files
- git add [filename]: adds file to current commit - git commit -m '[message]': add commit locally - git push origin master: push commit to your github repository
$ git diff data/northern.csv
diff --git a/report.txt b/report.txt
index e713b17..4c0742a 100644 --- a/report.txt +++ b/report.txt @@ -1,4 +1,5 @@ -# Seasonal Dental Surgeries 2017-18 +# Seasonal Dental Surgeries (2017) 2017-18 +# TODO: write new summary
- The command used to produce the output (in this case,
diff --git). In it,aandbare placeholders meaning "the first version" and "the second version". - An index line showing keys into Git's internal database of changes. We will explore these in the next chapter.
--- a/report.txtand+++ b/report.txt, wherein lines being removed are prefixed with-and lines being added are prefixed with+.- A line starting with
@@that tells where the changes are being made. The pairs of numbers arestart lineandnumber of lines(in that section of the file where changes occurred). This diff output indicates changes starting at line 1, with 5 lines where there were once 4. - A line-by-line listing of the changes
with
-showing deletions and+showing additions (we have also configured Git to show deletions in red and additions in green). Lines that haven't changed are sometimes shown before and after the ones that have in order to give context; when they appear, they don't have either+or-in front of them.
Git's equivalent of a relative path?
The special label HEAD,
which we saw in the previous chapter,
always refers to the most recent commit.
The label HEAD~1 then refers to the commit before it,
while HEAD~2 refers to the commit before that,
Show who changed what in what file
$ git log displays the overall history of a project or file.
$ git annotate report.txt : shows who made the last change to each line of a file and when.
$shows the differences between the commits git diff abc123..def456:abc123 and def456
$shows the differences between the state of the repository one commit in the past
and its state three commits in the past.git diff HEAD~1..HEAD~3:
How to Add New File
$ git status
$ git add XXX.csv
$ git commit -m "Test"
Ignore
.gitignore
if it contains
pdf
*.pyc
backupAll directory or file are ignoredgit clean -n will show you a list of files that are in the repository,
but whose history Git is not currently tracking.
A similar command git clean -f will then delete those files.
Use this command carefully:
git clean only works on untracked files,
so by definition,
their history has not been saved.
If you delete them with git clean -f,
they're gone for good.
$ git config
--system: settings for every user on this computer.--global: settings for every one of your projects.--local: settings for one specific project.
$ git config --list --local
$ git config --global user.email rep.loop@datacamp.com
$ git checkout -- filename: undo changesreset staged files
$ git reset HEAD path/to/file
$ git checkout -- path/to/file
$ git log -3 report.txt: shows the last 3 commits
$ git checkout 2242bd report.txt:replace the current version ofreport.txtwith the version that was committed on October 16. Notice that this is the same syntax that you used to undo the unstaged changes, except--has been replaced by a hash.
$ git reset HEAD directory: reset all files in the directory$git checkout -- directory: restore to the previous version
for current directory :$git checkout -- .
Branch:
$ git branch:Check branch
$ git diff branch-1..branch-2: see diff$ git checkout summary-statistics : to switch branch$ git rm report.txt : to delete file
$ git commit -m "Removing report" and $ls: just to make sure the file is goneto Create a branch: $git checkout -b branch-name
$ git merge source-branch-name destination-branch-name
$git init project-name: create a brand new repostory
$ git init /path/to/project : Turning an existing project into a Git repository?
$ git clone /existing/project new-project-name : copy existing repostory and name it
Find out where a cloned repository originated?
$ git remote
Git automatically creates a remote called origin
that points to the original repository.
$ git remote add remote-name URL(directory): add more remotes
$ git remote rm remote-name : remove remotePull in changes from a remote repository?
$ git pull remote-name branch-name
gets everything in branch in the remote repository identified by remote
and merges it into the current branch of your local repository. Push changes to a remote repository?
$ git push remote-name branch-name
没有评论:
发表评论