Git relative
===
[Create a remote Git repository from a local one]
On server:
- mkdir my_project.git
- cd my_project.git
- git --bare init
On client:
- git clone remote_myproject_path my_project
- cd my_project
- touch .gitignore
- git init
- git add .
- git commit -m "Initial commit"
- git remote add origin youruser@yourserver.com:/path/to/my_project.git
- git push origin master
[Create a empty branch]
git checkout --orphan <branch>
git rm -rf .
[Create a remote branch]
git push -u origin <branch>
[Delete a remote branch]
git push --delete <remote_name> <branch_name>
[Push to another repo's brach]
git remote add <name for remote> <remote path>
git push <remote name, e.g. origin> <local branch name>:<remote branch name>
[Print]
git log -n N # last N commit
git log --author=xxx # only xxx's commit
git log -L<start>,<end>:<filename> # show log only range in file
[Show diff between branches]
git log --no-merges --oneline <branc_1>..<branc_2> -- <folder_1> <folder_2> <file_3>
[am conflict]
git am xxx.patch # am patch, will get error
git apply --reject xxx.patch # generate .rej file, check confict part
git add relatived_files # add the file you want to commit
git am --resolved # finish commit and apply the commit content
[Generate a diff]
```
git diff -M <patch> <patch>
```
```
git format-patch -M ...
```
```
-M[<n>]
--find-renames[=<n>]
Detect renames. If n is specified, it is a threshold on the similarity index
(i.e. amount of addition/deletions compared to the file’s size). For example,
-M90% means Git should consider a delete/add pair to be a rename if more than 90% of the
file hasn’t changed. Without a % sign, the number is to be read as a fraction, with a
decimal point before it. I.e., -M5 becomes 0.5, and is thus the same as -M50%. Similarly, -M05
is the same as -M5%. To limit detection to exact renames, use -M100%. The default similarity index is 50%.
```
[Create empty folder]
create a file .gitignore
```
# Ignore everything in this directory
*
# Except this file
!.gitignore
```
[check commit number]
git shortlog -s -n remotes/origin/master arch/riscv/
[Modify commit date]
git commit --amend --date="$(date -R)"
[Modify config for auto sync to master branch]
1. git remote add origin <upstream_url>
2. edit config
```
[remote "origin"]
url = <upstream_url>
fetch = +refs/heads/master:refs/heads/master
```
3. git branch --set-upstream master origin/master (option)
4. use crontab -e
```
00 06 * * * cd <git_repo_path> && export http_proxy="http://cache1:3128/";export https_proxy="http://cache1:3128/";git fetch --all
```