From Electron Cloud
Jump to: navigation, search
(lsgit)
Line 30: Line 30:
  
 
==lsgit==
 
==lsgit==
<code>lsgit</code> is a script to list subdirectories which are git repositories, recursively, along with the branch or SHA1 of each.  It depends on /etc/bash_completion.d/git though for the __git_ps1 function.  (It would be better if I would find out the porcelain commands for that if possible, but I didn't.)
+
<code>lsgit</code> is a script to list subdirectories which are git repositories, recursively, along with the branch or SHA1 of each.  It depends on /etc/bash_completion.d/git though for the __git_ps1 function.  (It would be better if I would find out the porcelain commands for that if possible, but I didn't.) Working on Linux and OSX at least.
  
 
<pre>
 
<pre>
#!/bin/sh
+
#!/bin/bash
source /etc/bash_completion.d/git
+
if [ -f /usr/share/git/git-prompt.sh ]
for d in `find -name ".git" | sort`
+
then
 +
source /usr/share/git/git-prompt.sh
 +
fi
 +
if [ -f /etc/bash_completion.d/git ]
 +
then
 +
source /etc/bash_completion.d/git
 +
fi
 +
if [ -f /usr/local/etc/bash_completion.d/git-prompt.sh ]
 +
then
 +
source /usr/local/etc/bash_completion.d/git-prompt.sh
 +
fi
 +
for d in `/usr/bin/find . -name '.git' | sort`
 
do
 
do
        repopath=`dirname ${d}`
+
repopath=`dirname ${d}`
        pushd ${repopath} > /dev/null
+
pushd ${repopath} > /dev/null
        echo -e "$repopath \033[60G\033[33m `__git_ps1 %s` \033[0m"
+
echo -e "$repopath \033[60G\033[33m `__git_ps1 %s` \033[0m"
        if [ "$1" == '-v' ]; then
+
if [ "$1" == '-v' ]; then
                git status -uno
+
git status -uno
        fi
+
fi
        popd > /dev/null
+
popd > /dev/null
 
done
 
done
 
</pre>
 
</pre>

Revision as of 04:01, 4 December 2012

Easier merging when you know you always want "mine" or "theirs"

(Disclaimer: there could very well be a more elegant way which I don't know about; feel free to email if you know of one)

cp can be added as a "merge tool" which you can use selectively to accept one side or the other of merge conflicts automatically, without having to run a visual diff. (But it's a good idea to run visual diff or regular diff first to make sure whether you want the "local" or "remote" version!) Seems that so far in such cases I always want the "remote" version (in other words, the second version in the diff, or the non-HEAD version), so I just add cp in that direction as a "merge tool":

git config --global mergetool.accept-remote.cmd 'cp $REMOTE $MERGED'
git config --global mergetool.accept-remote.trustExitCode true

Usage:

git mergetool --tool=accept-remote [file ...]

and it will interact with you, something like this:

# git mergetool --tool=accept-remote
Merging:
file1.c
file2.h

Normal merge conflict for 'file1.c':
  {local}: modified
  {remote}: modified
Hit return to start merge resolution tool (accept-remote): 

...

and so on for each file to be merged.

lsgit

lsgit is a script to list subdirectories which are git repositories, recursively, along with the branch or SHA1 of each. It depends on /etc/bash_completion.d/git though for the __git_ps1 function. (It would be better if I would find out the porcelain commands for that if possible, but I didn't.) Working on Linux and OSX at least.

#!/bin/bash
if [ -f /usr/share/git/git-prompt.sh ]
then
	source /usr/share/git/git-prompt.sh
fi
if [ -f /etc/bash_completion.d/git ]
then
	source /etc/bash_completion.d/git
fi
if [ -f /usr/local/etc/bash_completion.d/git-prompt.sh ]
then
	source /usr/local/etc/bash_completion.d/git-prompt.sh
fi
for d in `/usr/bin/find . -name '.git' | sort`
do
	repopath=`dirname ${d}`
	pushd ${repopath} > /dev/null
	echo -e "$repopath \033[60G\033[33m `__git_ps1 %s` \033[0m"
	if [ "$1" == '-v' ]; then
		git status -uno
	fi
	popd > /dev/null
done