-
Notifications
You must be signed in to change notification settings - Fork 0
Git tricks
-
Just pull one file from remote repository:
$ git fetch community (remote repo)
$ git checkout community/develop (repo/branch) filename
-
git diff only show file names
$ git diff --name-only
-
diff one file
$ git diff mybranch master -- myfile.cs
or
$ git diff mybranch..master -- myfile.cs
-
check which files added in a commit
$ git diff-tree --no-commit-id --name-only -r 0ea1c630
-
merge upstream repository
$ git fetch upstream
$ git checkout master
$ git merge upstream/master
-
Add upstream repository
$ git remote -v
$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
- Get branch from another fork
$ git remote add theirusername git@github.com:theirusername/reponame.git
$ git fetch theirusername
$ git checkout -b mynamefortheirbranch theirusername/theirbranch
- remove files
$ git rm files (sometimes need to add --cache to only remove the file in index---keep file locally?)
remove directories
$ git rm -r dir
- compare fork with remote/upstream repo
first fetch upstream repo
git diff HEAD..mainRepo/master
- submodule
when .gitmodule is changed, try in the sub-directory "git submodule sync", then in the same dir "git submodule update --init --recursive"
check submodule commit: "git submodule status --recursive" or in the sub-directory "git ls-tree HEAD". The first one show current commit, later show target commit
.gitmodule branch just for reference. submodule will check out "git add " at the commit time
- find commit from which branch
git branch --contains
- add/remove submodules
add: git submodule add git@mygithost:billboard lib/billboard
remove:
1.remove section in .gitmodules
- git rm --cached lib/billboard
- delete branch
local branch: git -d
remote branch: git push --delete