git rev-list --reverse --topo-order master... | while read rev; do git checkout preview; git cherry-pick $rev || break; done

Cherry-pick range of commits, starting from the tip of 'master', into 'preview' branch

Creating feature-branches off master, and trying to merge them in an integration branch (preview), sometimes causes conflicts because the feature-branch might hold changes from 'master' that aren't on preview yet. So this ensures only the commits added to the feature-branch are moved to integration (preview). Note: This assumes you're currently on the feature-branch. Adjust 'master/preview' branch names to suit your environment.

-2
By: shadyvb
2015-04-23 14:28:06

These Might Interest You

  • Useful when quickly looking for a commit id from a branch to use with git cherry-pick. Show Sample Output


    3
    git log master | awk '/commit/ {id=$2} /\s+\w+/ {print id, $0}'
    root · 2009-01-28 13:32:08 0
  • This command will delete all branches in your git repository other than next and master. I use this to cleanup my git repos after making multiple branches and merging them back into next. It's much faster than individually deleting each expired branch using: git branch -D <branch_name>


    -1
    git branch -D `git branch | awk '{ if ($0 !~ /next|master/) printf "%s", $0 }'`
    denheck · 2011-04-14 17:43:21 0
  • To get the list of tickets in a comma-separated list, pipe the above into: sort | uniq | perl -pe 's/\n/, /' | sed 's/, $//' Show Sample Output


    0
    git log master...feature-a | grep -o -E '\b([A-Z]+)-[0-9]+\b' | sort | uniq
    westonruter · 2014-07-07 18:51:01 0
  • attempts to delete all local branches. git will fail on any branches not fully merged into local master, so don't worry about losing work. git will return the names of any successfully deleted branches. Find those in the output with grep, then push null repositories to the corresponding names to your target remote. assumes: - your local and remote branches are identically named, and there's nothing extra in the remote branch that you still want - EDIT: you want to keep your local master branch


    0
    git branch | cut -c3- | grep -v "^master$" | while read line; do git branch -d $line; done | grep 'Deleted branch' | awk '{print $3;}' | while read line; do git push <target_remote> :$line; done
    gocoogs · 2011-08-13 16:58:34 0
  • Outputs a quick summary of the svn commits for a user over a date range with the detail revision logs including comments and files affected. Useful for searching for a particular change or reporting by user. Show Sample Output


    1
    for i in `svn log -r{2011-02-01}:HEAD | awk '$3 == "user" {print $1}'`; do svn log -v -$i;done
    vijayphadke · 2011-03-04 17:11:22 0
  • Description by segments delimited by pipe (|) 1. List all git branches 2. Exclude master 3. Trim output and remove display elements such as * next to current branch 4. Repeat branch name after a space (output on each line: branch_name branch_name) 5. Prepend each line with the git tag command 6. Execute the output with bash


    0
    git branch | grep -v "master" | sed 's/^[ *]*//' | sed 's/.*/& &/' | sed 's/^/git tag archive\//' | bash
    Trindaz · 2015-01-31 00:26:15 0

What Others Think

They say a picture is worth a thousand words. Would you like to draw one to show what this command's doing?
flatcap · 160 weeks and 5 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: