Git uses blob object to store the conent of file of each version, the blog file name is SHA1 value of content of file.
Git uses tree object to store the filename/path and corresponding blob data.
git ls-files -s, to list all files
git ls-remote, to list remotes and branchs
The default file .gitignore who contains the ignore files in each folder.
HEAD is a reference to the last commit in the currently check-out branch.
downstream when you copy (clone, checkout, etc) from a repository
upstream generally refers to the original repo that you have forked
create a remote repository in local file
in folder, git init -bare
The first step
in the selected folder
git init
git remote add origin remote-address
or
git clone remote address
or git clone -b branchname remoteaddress
Note that, git clone also can clone two folders in local. for instance, git clone oldfolder newfolder
==========================================
Add a new file
git add files
git commit -m"comments"
git push
While a already commited file is modified, just git commit and git push are enough.
delete files
git rm files
git commit -m"comments"
git push
rename file or folder
git mv oldfile newfile
git push
show status
git status
git branch -aav to see the branch information including the remote and local
check the history
git log
git log --oneline, show the change in one line comprehensive
git show 9da581d910c9c4ac93557ca4859e767f5caf5169/or short name to see what‘s the detail changes
git show-branch to get the sumary of current development branch
git diff 9da581d910c9c4ac93557ca4859e767f5caf5169 9da581d910c9c4ac93557ca4859e767f5caf5199 to check the difference between two commits.
gitk the graph view of changes
git log -p filename, it view the history of the file.
git log --graph --oneline, graph way to display with log
git diff
git diff --name-only master origin/master
Configuration
git config --global user.name "your name here"
git config --global user.email "your email here"
git config -l list all configured
.gitignore
.gitignore file
Ignoring the file everywhere by adding it to the .gitignore file in the topmost directory of repository. Multi .gitignore file in different directories is accepted, it only applies for current directory and sub directoies.
To ignore .o files, place *.o in your top level .gitignore
branch
git branch newbranchname [start-commit], it will create a branch name, but still system still working in current branch, the [start-commit] is to select which branch as the starting of the new branch, it is option, the default the current working branch.
git show-branch, shows the branch in local and remote
git checkout newworkbranch switch to work branch
example:
git branch Sprint-1
git show-branch
the current working branch is master (*)
git checkout Sprint-1
now, it switches to Sprint-1(*)
commit somefile with git add ., git commit
push to server, git push, the errro will be indicated:
git checkout -b newbranchname [start-point], create and switch to new branch
git branch -d branchname, delete a branch
git branch -vv to track and show local and remote branchs
general working flow:
create a branch in local, git checkout -b newbranchname
work as you want, git add . git commit .
git push -u origin newbrachname, it will auto push to remote with newbranchname
merge
git merge development master //merge local development to local master, but now we still in the development branch
git push origin master //push to remote, the orgin master
===========================================================
problems Solve
fatal: refusing to merge unrelated histories
git pull --allow-unrelated-histories
visit local reponsitory without proxy: fatal: repository ‘http://server:8080/tfs/DefaultCollection/_git/PlayProject/‘ not found
git config --local remote.origin.proxy ""
the "origin" is alias of remote.
git config --list, to list all configurations
git remote show origin, it is to show the URL of remote/origin
in case the error is shown when run git remote show origin,
we can use command to fix it. git remote set-url origin theremoteurl
原文:https://www.cnblogs.com/zjbfvfv/p/10554630.html