8/15/2023 0 Comments Git list branches by creation date![]() ![]() If you're new to using pull requests and just want to see what steps you should follow, here's my git pull request checklist which you may find helpful. What if you want to keep the branch around so you can always go back and see when it was merged? We'll get to that at the end of this post. You can create another branch, and even give it the same name, but don't recycle branches you've already associated with a pull request for use with any other work. Reusing the patch-1 branch (after its original PR has been merged and closed) is a good way to cause problems in your git repository. At this point, the pull request is complete, and future commits should only be made on master, not patch-1. After the merge (assuming a new merge commit is added), both master and patch-1 point to a new merge commit. Use git branch -sort-committerdate to display a list of all local branches and sort them based on the date of their last commit. Before the merge, master and patch-1 both point to separate commits in git's commit history. Prints a list of all local branches sorted by date. Consider a scenario in which a branch patch-1 is about to be merged with the master branch through a pull request. They don't add any significant technical overhead, but they make it more difficult for humans to work with lists of branches in the repository.īranches can be safely removed without risk of losing any changes. In most cases, branches, especially branches that were related to a pull request that has since been accepted, serve no purpose. Why should you delete old branches from your git repositories? There are two main reasons: Using GitHub's GraphQL API which is accessible here, we can do it with two different queries and a tiny bit of experimentation and searching.It's a common housekeeping practice to delete git branches once they're no longer used, but this practice isn't necessarily universal, or universally understood. In the default 'medium' type git log output the 'author date' is shown. The above commands use the author date %as but you can get the committer date by replacing the %a for %c like %cs. Note that Git keeps track of both the 'author date' and the 'committer date'. But a reversed list can be easier to work with if you need more details, like I show in my example to print the commit metadata. You could use tail instead of head for example. Note that there is no need to reverse if you format and use other commands to filter the relevant commit. ![]() Just select the 3 lines that summarize the commit details as git log does in the normal output. $ git log -reverse -date="format:%Y" -format="format:%ad" | head -n 1 And here we can use additional formatting %Y to select just the year. Get the date in ISO 8601 format of the first commit $ git log -reverse -format="format:%aI" -all | head -n 1īy using %ad output format, the -date format is respected. $ git log -reverse -format="format:%as" -all | head -n 1 Using the %as format to display the author date in short format. The -list flag can be used to filter branches by keywords or patterns. For example, to list branches in alphabetical order, run git branch -sortname. You can use the formatting options to get the output you like. Here are some techniques for filtering and sorting Git branches: You can use the -sort flag with the git branch command to sort branches by various criteria, such as date or name. This will get you the last page: git.php Īs Git applies the -reverse after any filtering of commits, you need to output -all commits and use other commands to restrict the output.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |