LoginSignup
3
4

More than 5 years have passed since last update.

gitのコミット(commit)とマージ(merge)とトピックブランチの削除

Posted at

書く動機

Rails チュートリアルで学んだことを覚えるために書く。

変更が終わったトピックブランチの状態を見る git status

command
$ git status
On branch test
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   nokonoko.rb
no changes added to commit (use "git add" and/or "git commit -a")

コミット git commit -a -m "コメント"

-aフラグはすべてのファイルへの変更を一括でコミットすることが出来る。

command
$ git commit -a -m "nokogiri_sample revised"
[test 60734eb] nokogiri_sample revised
 1 file changed, 2 insertions(+), 2 deletions(-)

マージ git merge <ブランチ名>

ブランチでのファイル変更が終わったので、マスターブランチに切り替えて、git merge <ブランチ名>コマンドでマスターブランチに変更を反映する。

command
$ git checkout master
Switched to branch 'master'
$ git merge test
Updating 5a58185..5d8a1ce
Fast-forward
 nokonoko.rb | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

トピックブランチの削除 git branch -D <トピックブランチ名>

この時点でトピックブランチが残っています。
トピックブランチを削除せずにそのまま残しておくことはよくあるそうですが、作成したトピックブランチが不要になったりすることもあるので、書いておく。
例では、トピックブランチtestを削除してみる。

command
$ git branch
* master
  test

$ git branch -D test
Deleted branch test (was 5d8a1ce).

$ git branch
* master
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4