Git: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
=== TASKS === | === TASKS === | ||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! git merging conflicts after diverging | |||
|- | |||
| Revert local changes in a file to HEAD | |||
git checkout -- path/to/file.txt | |||
Discard ALL LOCAL COMMITS and get the (possibly diverged) remote instead | |||
git reset --hard origin/master | |||
|} | |||
{| class="mw-collapsible mw-collapsed wikitable" | {| class="mw-collapsible mw-collapsed wikitable" | ||
! git create new branch on server, pull to client | ! git create new branch on server, pull to client | ||
Line 67: | Line 75: | ||
git checkout master | git checkout master | ||
git branch -u origin/master master | git branch -u origin/master master | ||
|} | |} | ||
Line 96: | Line 95: | ||
Then you can clean up old branches like daily and daily_grind, as needed. | Then you can clean up old branches like daily and daily_grind, as needed. | ||
|} | |} | ||
{| class="mw-collapsible mw-collapsed wikitable" | {| class="mw-collapsible mw-collapsed wikitable" | ||
! git create merge-to command | ! git create merge-to command | ||
Line 175: | Line 172: | ||
| | | | ||
git config --global push.default current | git config --global push.default current | ||
|} | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! git multiple upstreams | |||
|- | |||
| Use this to cause AUTOMATIC push/pull to a second origin: | |||
git remote set-url origin --push --add user1@repo1 | |||
git remote set-url origin --push --add user2@repo2 | |||
git remote -v show | |||
Leave out --push if you want to pull as well... but I'd be careful, it's better if code is changed in one client with this config, and then pushed to the multiple origins from there. Otherwise, things are GOING TO GET SYNCY-STINKY. | |||
|} | |} | ||
Revision as of 13:35, 13 April 2016
TASKS
git merging conflicts after diverging |
---|
Revert local changes in a file to HEAD
git checkout -- path/to/file.txt Discard ALL LOCAL COMMITS and get the (possibly diverged) remote instead git reset --hard origin/master |
git create new branch on server, pull to client |
---|
# ON CENTRAL SERVER git checkout master # as needed; we are assuming that master is clean enough as a starting point git checkout -b mynewbranchy # HOWEVER, use this instead if you need a new "clean" repo and even master is dirty... # You need the rm because git "leaves your working folder intact". git checkout --orphan mynewbranchy git rm -rf . # ON CLIENT git pull git checkout -b mynewbranchy origin/mynewbranchy # if files are in the way from the previously checked-out branch, you can force it... git checkout -f -b mynewbranchy origin/mynewbranchy |
git pull when untracked files are in the way |
---|
This will pull, forcing untracked files to be overwritten by newly tracked ones in the repo:
git fetch --all git reset --hard origin/mymatchingbranch |
git create new branch when untracked files are in the way |
---|
git checkout -b bj143 origin/bj143 git : error: The following untracked working tree files would be overwritten by checkout: (etc) TOTAL PURGE FIX (too much): git clean -d -fn "" -d dirs too -f force, required -x include ignored files (don't use this) -n dry run BEST FIX (just overwrite what is in the way): git checkout -f -b bj143 origin/bj143 |
git recreate repo |
---|
git clone ssh://m@thedigitalmachine.com/home/m/development/thedigitalage/ampache-with-hangthedj-module cd ampache-with-hangthedj-module git checkout -b daily_grind origin/daily_grind If you already have the daily_grind branches and just need to connect them: git branch -u origin/daily_grind daily_grind |
git connect to origin after the fact |
---|
git remote add origin ssh:// m@bitpost.com/home/m/development/logs git fetch From ssh:// bitpost/home/m/development/logs * [new branch] daily_grind -> origin/daily_grind * [new branch] master -> origin/master git branch -u origin/daily_grind daily_grind git checkout master git branch -u origin/master master |
CONFIGURATION
git convert to a bare repo |
---|
Start with a normal git repo via [git init]; add your files, get it all set up. Then do this:
cd repo Now you can copy-paste this... mv .git .. && rm -fr * mv ../.git . mv .git/* . rmdir .git git config --bool core.bare true cd .. Don't copy/paste these, you need to change repo name... mv repo repo.git # rename it for clarity git clone repo.git # (optional, if you want a live repo on the server where you have the bare repo) Then you can clean up old branches like daily and daily_grind, as needed. |
git create merge-to command |
---|
Add this handy alias command to all git repos' .config file...
[alias] merge-to = "!gitmergeto() { export tmp_branch=`git branch | grep '* ' | tr -d '* '` && git checkout $1 && git merge $tmp_branch && git checkout $tmp_branch; unset tmp_branch; }; gitmergeto" |
git fix github diverge from local bare repo following README.md edit |
---|
Yes editing the README.md file on github will FUCK UP your downstream bare repo if you meanwhile push to it before pulling.
Fixing it is a PAIN in the ASS, you have to create a new local repo and pull github into that, pull in from your other local repo, push to github, pull to your bare... git clone git@github.com:moodboom/quick-http.git quick-http-with-readme-conflict git remote add local ../quick-http git fetch local git merge local/master # merge in changes, likely trivial git push # pushes back to github cd .. mv quick-http.git quick-http.git__gone-out-of-sync-fu-github-readme-editor git clone git@github.com:moodboom/quick-http.git --bare cp quick-http.git__gone-out-of-sync-fu-github-readme-editor/config quick-http.git/ And that MIGHT get you on your way... but I would no longer trust ANY of your local repos... This is a serious pita. |
git use kdiff3 as difftool and mergetool |
---|
It's been made easy on linux...
[diff] tool = kdiff3 [merge] tool = kdiff3
[difftool "kdiff3"] path = C:/Progra~1/KDiff3/kdiff3.exe trustExitCode = false [difftool] prompt = false [diff] tool = kdiff3 [mergetool "kdiff3"] path = C:/Progra~1/KDiff3/kdiff3.exe trustExitCode = false [mergetool] keepBackup = false [merge] tool = kdiff3
[difftool "kdiff3"] path = /usr/bin/kdiff3 trustExitCode = false [difftool] prompt = false [diff] tool = kdiff3 [mergetool "kdiff3"] path = /usr/bin/kdiff3 trustExitCode = false [mergetool] keepBackup = false [merge] tool = kdiff3 |
git windows configure notepad++ editor |
---|
git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin" |
git fix push behavior - ONLY PUSH CURRENT doh |
---|
git config --global push.default current |
git multiple upstreams |
---|
Use this to cause AUTOMATIC push/pull to a second origin:
git remote set-url origin --push --add user1@repo1 git remote set-url origin --push --add user2@repo2 git remote -v show Leave out --push if you want to pull as well... but I'd be careful, it's better if code is changed in one client with this config, and then pushed to the multiple origins from there. Otherwise, things are GOING TO GET SYNCY-STINKY. |
From here...