Rename remote branch without deleting it
Quick oneliner for deleting old branch and creating a new one with same content is:
git push <remote> <remote>/<old>:refs/heads/<new> :<old>
where
remote
is obvious – e.g. origin,old
andnew
are names of branches old and new respectively.
Git
How to copy a file or directory from another GIT repository while preserving its history?
Internet is full of magic formulas each one more complex.
Here I’m proposing a much simpler and faster one that is to make a git format-patch for the entire history of the file or subdirectory that we want and then import it into the destination repository.
mkdir /tmp/mergepatchs cd ~/repo/org export reposrc=myfile.c #or mydir git format-patch -o /tmp/mergepatchs $(git log $reposrc|grep ^commit|tail -1|awk '{print $2}')^..HEAD $reposrc cd ~/repo/dest git am /tmp/mergepatchs/*.patch
Simple and fast
Source synaptic fault http://blog.neutrino.es/2012/git-copy-a-file-or-directory-from-another-repository-preserving-history/
Never* use git pull – YouTube
Just a quick summary mostly for myself:
How to use git pull --rebase
to keep your team’s commit history clean.
Command for creating the ‘git pr
‘ alias (so you can copy-paste): git config --global alias.pr "pull --rebase"
- Always try
git pull --rebase
first. It if works, you’re done! - If you get a merge conflix, you can undo everything with
git rebase --abort
- Then just pull “normally” using
git pull
, or do an interactive rebase (advanced)
Find and restore a deleted file in a Git repository
Use
git log --diff-filter=D --summary
to get all the commits which have deleted files and the files deleted;- Use
git checkout $commit~1 filename
to restore the deleted file.
Sorgente: Find and restore a deleted file in a Git repository – Stack Overflow