branch

如何在Git中获取当前的分支名称?

♀尐吖头ヾ 提交于 2020-01-08 20:57:57
我来自Subversion的背景,当我有一个分支时,我知道我正在使用“这些工作文件指向此分支”的内容。 但是使用Git时,我不确定在NetBeans或Notepad ++中编辑文件时,是将文件绑定到主文件还是其他分支。 bash中的 git 没问题,它告诉我我在做什么。 #1楼 好简单,我把它放在一根衬里(bash) git branch | sed -n '/\* /s///p' (信用:有限赎罪) 当我在那里的时候,一个班轮去了远程跟踪分支机构(如果有的话) git rev-parse --symbolic-full-name --abbrev-ref @{u} #2楼 您还可以使用 git symbolic-ref HEAD 来显示完整的refspec。 在Git v1.8及更高版本中仅显示分支名称(感谢Greg指出): $ git symbolic-ref --short HEAD 在Git v1.7 +上,您还可以执行以下操作: $ git rev-parse --abbrev-ref HEAD 如果您在分支机构上,则两者都应使用相同的分支机构名称。 如果您是一个超脱的人,答案会有所不同。 注意: 在较早的客户端上,这似乎可行: $ git symbolic-ref HEAD | sed -e "s/^refs\\/heads\\///" – 达里安2014年3月26日

怎么让自己的fork与author同步

冷暖自知 提交于 2020-01-08 19:54:12
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 问: I have forked a github project, then cloned it locally. I then made some changes in a new branch on my_github/the_project repo. I then added and committed the changes and pushed to my github repo and submitted a pull request. The owner has received my request and would like me to "rebase onto master" to get the latest changes. How do I do this? Initially I thought I could just git fetch and rebase master from within my current branch (as most posts I found advise...), but git fetch didn't do anything. Now I've realized that it is presumably because I'm

Git常用命令及场景

末鹿安然 提交于 2020-01-08 10:15:51
Git命令推送到远程分支 1、登录GitHub创建一个远程仓库。    https://github.com                2、git init   本地创建一个目录,并初始化一个git仓库。 3、git add   添加文件到当前目录下,然后执行git add ,将“修改”从当前工作区存放到暂存区。 4、git commit -m "注释语句"   将暂存区中存放的文件提交到本地git仓库。 5、git remote add origin https://远程仓库地址   将本地代码库的当前分支与远程的代码库分支相关联。 6、git pull origin master   远程库分支更新代码到本地。 7、git push -u origin master(远程分支)   将本地代码库的当前分支推送到远程的代码库。 如果如下报错 failed to push some refs to 'https://github.com/kosamino/demo.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint

git 的简单命令

孤者浪人 提交于 2020-01-07 17:41:57
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> git init git add file.txt 添加 git commit -m "XXX" 提交 git status git diff git log 查看提交历史 git log --pretty=oneline 历史一行一行显示 git reset --hard head^(回退到上一个版本) git reset --hard 版本号前几位 git reflog 查看命令历史 git checkout -- readme.txt 丢弃工作区的修改 git reset HEAD file 不但改乱了⼯工作区某个⽂文件的内容,还添加到了暂存区时,想丢弃修改,分两步 1、reset 2、checkout 删除文件: rm 文件名 git rm 文件名 git commit -m "rm 文件名" rm 文件名 git checkout -- test.txt $ git push origin master 本地master分⽀支的最新修改推送⾄至GitHub git remote add origin git@server-name:path/repo-name.git ; 关联一个远程库 git push -u origin master 第一次推送master分⽀支的所有内容; 从远程库克隆 git

git拉取远程分支并创建本地分支

ぃ、小莉子 提交于 2020-01-07 11:32:33
一、查看远程分支 使用如下git命令查看所有远程分支: git branch -r 查看远程和本地所有分支: git branch -a 查看本地分支: git branch 在输出结果中,前面带 * 的是当前分支。 二、拉取远程分支并创建本地分支 方法一 使用如下命令: git checkout -b 本地分支名x origin/远程分支名x 使用该方式会在本地新建分支x,并自动切换到该本地分支x。 采用此种方法建立的本地分支会和远程分支建立映射关系。 方式二 使用如下命令: git fetch origin 远程分支名x:本地分支名x 使用该方式会在本地新建分支x,但是不会自动切换到该本地分支x,需要手动checkout。 采用此种方法建立的本地分支不会和远程分支建立映射关系。 三、本地分支和远程分支建立映射关系的作用 建立本地分支与远程分支的映射关系(或者为跟踪关系track)。 这样使用git pull或者git push时就不必每次都要指定从远程的哪个分支拉取合并和推送到远程的哪个分支了。 git branch -vv 上面的本地分支和远程分支都有映射关系,如果没有,就需要手动建立: git branch -u origin/分支名 , 或者 git branch --set-upstream-to origin/分支名 origin 为git地址的标志

如何获得最近提交的Git分支列表?

柔情痞子 提交于 2020-01-07 04:17:47
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我想得到一个Git存储库中所有分支的列表,顶部有“最新鲜”的分支,其中“最新鲜”的分支是最近提交的分支(因此,更可能是一个分支)我想要注意)。 有没有办法可以使用Git(a)通过最新提交对分支列表进行排序,或者(b)以某种机器可读格式获取分支列表以及每个分支的最后提交日期? 最糟糕的情况是,我总是可以运行 git branch 来获取所有分支的列表,解析其输出,然后 git log -n 1 branchname --format=format:%ci 为每个分支,以获得每个分支的提交日期。 但是这将在Windows机器上运行,其中启动新进程相对昂贵,因此如果有很多分支,每个分支启动Git可执行文件可能会变慢。 有没有办法用一个命令完成所有这些? #1楼 这是最佳代码,它结合了另外两个答案: git for-each-ref --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(authorname) %(refname:short)' #2楼 这是一个简单的命令,列出了最新提交的所有分支: git branch -v 要按最近提交的顺序排序,请使用 git branch -v --sort=committerdate 来源:

如何更改远程分支正在跟踪?

天涯浪子 提交于 2020-01-06 17:00:15
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 必须在新服务器上设置 central 存储库,因此我在本地存储库上创建了一个新的远程存储库,然后将其推送到该服务器。 但现在当我做 git pull ,它声称我是最新的。 这是错的 - 它告诉我关于 旧的 远程分支,而不是新的远程分支,我知道事实上有新的提交提取。 如何更改本地分支以跟踪不同的遥控器? 我可以在git配置文件中看到这个,但我不想搞砸了。 [branch "master"] remote = oldserver merge = refs/heads/master #1楼 git fetch origin git checkout --track -b local_branch_name origin/branch_name 要么 git fetch git checkout -b local_branch_name origin/branch_name #2楼 对我来说,修复是: git remote set-url origin https://some_url/some_repo 然后: git push #3楼 使用最新的git(2.5.5)命令如下: git branch --set-upstream-to=origin/branch 这将更新当前本地分支的远程跟踪分支 #4楼

2 svn -> 1 git. How to map two svn repositories into one git with two branches with common origin?

ⅰ亾dé卋堺 提交于 2020-01-06 15:14:38
问题 The project I work on was divided on 2 projects one year ago. For this svn repository was copied to another location and work was continued into 2 different svn repositories. Now I have to merge these 2 projects into one. For these I would like to have a local git repository with 2 branches, each of those mapped to one of svn repositories. Is it possible? I know that I can create 2 remotes branches in git, but how to explain git that these branches have a common origin? 来源: https:/

Subversion merge trunk into existing tag

我怕爱的太早我们不能终老 提交于 2020-01-06 06:11:40
问题 I'm currently having the following setup in my SVN-repository: -Root --ProjectA ----trunk ----tags ----branches --ProjectB ----trunk ----tags ----branches --ProjectPool ----projectA ----projectB Where ProjectPool contains specific tags of ProjectA and ProjectB. Now the tags in ProjectPool change from time to time. This means a specific trunk-version of ProjectA is commited and I want to create a copy from this revision into Root/ProjectPool/projectA. The new tag should replace the old tag,

Subversion merge trunk into existing tag

守給你的承諾、 提交于 2020-01-06 06:10:24
问题 I'm currently having the following setup in my SVN-repository: -Root --ProjectA ----trunk ----tags ----branches --ProjectB ----trunk ----tags ----branches --ProjectPool ----projectA ----projectB Where ProjectPool contains specific tags of ProjectA and ProjectB. Now the tags in ProjectPool change from time to time. This means a specific trunk-version of ProjectA is commited and I want to create a copy from this revision into Root/ProjectPool/projectA. The new tag should replace the old tag,